-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlugin.php
1192 lines (1108 loc) · 63.7 KB
/
Plugin.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* OneCircle:
* 后台接口,增加用户个人签名设置<br>
* 加入了权限设置:修改注册时默认用户组,贡献者可直接发布文章无需审核,前台注册支持用户输入密码<br>
* @package OneCircle
* @author gogobody
* @version 4.6
* @link https://one.ijkxs.com
*/
require(__DIR__ . DIRECTORY_SEPARATOR . "Action.php");
require(__DIR__ . DIRECTORY_SEPARATOR . 'core/utils/JKUtils.php');
require(__DIR__ . DIRECTORY_SEPARATOR . 'core/handler/handler.php');
// require abstrace
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Abstract/Credits.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Abstract/Notice.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Abstract/Message.php");
// require handler
require_once 'pages/metas/Metasmanage.php';
require_once 'pages/neighbor/Widget_Neighbor.php';
require_once 'pages/blog/Widget_blog.php';
require_once 'pages/usercenter/Widget_usercenter.php';
require_once 'pages/notices/Widget_notices.php';
require_once 'pages/messages/Widget_messages.php';
// require widget
require_once(__DIR__ . DIRECTORY_SEPARATOR . "manage/Widget_CateTag_Edit.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/upload.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Credits.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Common.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Users/Query.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Credits/List.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Notices/List.php");
require_once(__DIR__ . DIRECTORY_SEPARATOR . "widget/Messages/List.php");
class OneCircle_Plugin extends Widget_Archive implements Typecho_Plugin_Interface
{
// 默认加密首尾标签对 // 不要修改
protected static $pluginNodeStart = '<!--jkhelper start-->';
protected static $pluginNodeEnd = '<!--jkhelper end-->';
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
// plugin handle
// 自定义页面
// $author = array (
// 'url' => '/author/[uid:digital]/',
// 'widget' => 'Widget_Archive',
// 'action' => 'render',
// );
// $this->_defaultRegx = array(
// 'string' => '(.%s)',
// 'char' => '([^/]%s)',
// 'digital'=> '([0-9]%s)',
// 'alpha' => '([_0-9a-zA-Z-]%s)',
// 'alphaslash' => '([_0-9a-zA-Z-/]%s)',
// 'split' => '((?:[^/]+/)%s[^/]+)',
// );
// /**
// * 支持的过滤器列表
// *
// * @access private
// * @var string
// */
// private static $_supportFilters = array(
// 'int' => 'intval',
// 'integer' => 'intval',
// 'search' => array('Typecho_Common', 'filterSearchQuery'),
// 'xss' => array('Typecho_Common', 'removeXSS'),
// 'url' => array('Typecho_Common', 'safeUrl'),
// 'slug' => array('Typecho_Common', 'slugName')
// );
Helper::addRoute('metas', '/metas/', 'Widget_Archive@meta', 'render');
/** 这里要注意区分不同的 archive 实例 */
Helper::addRoute('neighbor_page', '/neighbor/[keyword]/[page:digital]/', 'Widget_Archive@neighbor_page', 'render');
Helper::addRoute('neighbor', '/neighbor/[keyword]/', 'Widget_Archive@neighbor', 'render');
Helper::addRoute('myblog', '/myblog/', 'Widget_Archive@myblog', 'render');
Helper::addRoute('myblog_page', '/myblog/[page:digital]/', 'Widget_Archive@myblog_page', 'render');
Helper::addRoute('setting', '/usercenter/setting', 'Widget_Archive@usercenter_settiing', 'render');
Helper::addRoute('credits', '/usercenter/credits', 'Widget_Archive@usercenter_credits', 'render');
Helper::addRoute('notice', '/usercenter/notice', 'Widget_Archive@notice', 'render');
Helper::addRoute('messages', '/usercenter/messages', 'Widget_Archive@messages', 'render');
// 路由注册
// 资源专区
Helper::addRoute('resources', '/resources', 'Widget_Archive@resources', 'render');
Helper::addRoute('resources_page', '/resources/[page:digital]/', 'Widget_Archive@resources_page', 'render');
// 热门文章
Helper::addRoute('hotposts', '/hot/posts', 'Widget_Archive@hotposts', 'render');
Helper::addRoute('hotposts_page', '/hot/posts/[page:digital]/', 'Widget_Archive@hotposts_page', 'render');
// 页面注册
Typecho_Plugin::factory('Widget_Archive')->handleInit_1000 = array('OneCircle_Plugin','handleInit');
Typecho_Plugin::factory('Widget_Archive')->handle_1000 = array('OneCircle_Plugin','handle');
// 修改注册用户上传权限
Typecho_Plugin::factory('Widget_Upload')->uploadHandle_1000 = array('OneCircle_Plugin','uploadHandle');
// 打赏模块
Typecho_Plugin::factory('OneCircle.Donate')->Donate = array('OneCircle_Plugin', 'Donate');
// 注册用户权限管理
Typecho_Plugin::factory('Widget_Register')->register_1000 = array('OneCircle_Plugin', 'zhuce');
Typecho_Plugin::factory('Widget_Register')->finishRegister_1000 = array('OneCircle_Plugin', 'zhucewan');
Typecho_Plugin::factory('Widget_Contents_Post_Edit')->write_1000 = array('OneCircle_Plugin', 'fabu');
Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish_1000 = array('OneCircle_Plugin', 'fabuwan');
Typecho_Plugin::factory('admin/footer.php')->end_1000 = array('OneCircle_Plugin', 'footerjs');
// 积分
Typecho_Plugin::factory('Widget_Login')->loginSucceed_1000 = array('OneCircle_Plugin', 'loginSucceed');
Typecho_Plugin::factory('Widget_Feedback')->finishComment_1000 = array('OneCircle_Plugin', 'finishComment');
// 添加 关注圈子
OneCircle_Plugin::userCircleFollowInstall();
// 添加个人简介字段
OneCircle_Plugin::userSignsqlInstall();
OneCircle_Plugin::userTagsqlInstall();
// 添加分类标签字段
OneCircle_Plugin::metasTypesqlInstall();
// 添加 用户头像
OneCircle_Plugin::userAvatarsqlInstall();
OneCircle_Plugin::userBackImgsqlInstall();
// 添加 用户性别
OneCircle_Plugin::userSexsqlInstall();
// 添加文章额外字段
OneCircle_Plugin::contentsSqlInstall();
OneCircle_Plugin::typecho_TableInstall();
OneCircle_Plugin::userExtendsqlInstall();
// 2021/9/1 添加消息
//
// 积分阅读
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx_1001 = array(__CLASS__, 'contentEx');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx_1001 = array(__CLASS__, 'excerptEx');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array(__CLASS__, 'writeRender');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array(__CLASS__, 'writeRender');
// register apis
Helper::addRoute('jsonp_', '/jkhelper/[type]', 'OneCircle_Action');
// action method url : /action/oneapi
// Helper::addAction('oneapi', 'OneCircle_Action');
// route method url : /oneaction
// /action/whosurdaddy
Helper::addRoute("one_action", "/oneaction", "OneCircle_Action", 'route');
Helper::addPanel(3, 'OneCircle/manage/manage-cat-tags.php', '管理圈子分类', '圈子分类', 'administrator'); //editor //contributor
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
*/
public static function deactivate()
{
Helper::removeRoute('one_action');
Helper::removeRoute('metas');
Helper::removeRoute('neighbor');
Helper::removeRoute('neighbor_page');
Helper::removeRoute('myblog');
Helper::removeRoute('myblog_page');
Helper::removeRoute('setting');
Helper::removeRoute('credits');
Helper::removeRoute('jsonp_');
Helper::removePanel(3, 'OneCircle/manage/manage-cat-tags.php');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$options = Helper::options();
$pluginV = get_plugins_info();
?>
<div class="j-setting-contain">
<link href="<?php echo $options->themeUrl('/assets/admin/css/one.setting.min.css','onecircle') ?>" rel="stylesheet" type="text/css" />
<div>
<div class="j-aside">
<div class="logo">ONE <?php echo $pluginV ?><br><small style="font-size: 10px"></small><br>
<a href="/admin/options-theme.php" target="_self" rel="noopener noreferrer">点我去主题设置</a></div>
<ul class="j-setting-tab">
<li data-current="j-setting-global">公共设置</li>
<li data-current="j-setting-qrcode">二维码设置</li>
<li data-current="j-setting-resource">资源设置</li>
</ul>
<?php require_once('Backups.php'); ?>
</div>
</div>
<span id="j-version" style="display: none;"><?php echo $pluginV; ?></span>
<div class="j-setting-notice"><iframe src="https://www.yuque.com/docs/share/05f40cac-980f-4e53-8b92-ed9728b8dc50?# 《OneCircle 主题说明》" frameborder="no" scrolling="yes" height="100%" width="100%"></iframe></div>
<script src="<?php echo $options->themeUrl('/assets/admin/js/one.setting.min.js','onecircle')?>"></script>
<?php
/** 分类名称 */
// $name = new Typecho_Widget_Helper_Form_Element_Text('word', NULL, 'Hello World', '说点什么');
// $form->addInput($name);
$yonghuzu = new Typecho_Widget_Helper_Form_Element_Radio('yonghuzu', array(
'visitor' => '访问者',
'subscriber' => '关注者',
'contributor' => '贡献者',
'editor' => '编辑',
'administrator' => '管理员'
), 'contributor', '注册用户默认用户组设置', '<p class="description">不同的用户组拥有不同的权限,具体的权限分配表请<a href="http://docs.typecho.org/develop/acl" target="_blank" rel="noopener noreferrer">参考这里</a>.</p>');
$yonghuzu->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($yonghuzu);
$tuozhan = new Typecho_Widget_Helper_Form_Element_Checkbox('tuozhan',
array('contributor-nb' => '勾选该选项让【贡献者】直接发布文章无需审核',
'register-nb' => '勾选该选项后台注册功能将可以直接设置注册密码',
),
array('contributor-nb','register-nb'), '拓展设置', '');
$tuozhan->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($tuozhan->multiMode());
//
$db = Typecho_Db::get();
$select = $db->select('mid')->from('table.metas');
$row = $db->fetchRow($select);
if (!empty($row)) $umid = $row['mid'];
else $umid = 1;
$registeruserMid = new Typecho_Widget_Helper_Form_Element_Text('registeruserMid', NULL, $umid, '用户注册后默认关注哪个分类(int)');
$registeruserMid->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($registeruserMid);
$focususerMid = new Typecho_Widget_Helper_Form_Element_Text('focususerMid', NULL, 1, '发布关注消息到哪个分类(int)');
$focususerMid->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($focususerMid);
$amapJsKey= new Typecho_Widget_Helper_Form_Element_Text('amapJsKey', NULL, '', '高德地图 Web端(JS API key');
$amapJsKey->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($amapJsKey);
$amapWebKey= new Typecho_Widget_Helper_Form_Element_Text('amapWebKey', NULL, '', '高德地图 Web服务 key');
$amapWebKey->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($amapWebKey);
$allowNoneAdminUpload = new Typecho_Widget_Helper_Form_Element_Radio('allowNoneAdminUpload',array(
1 => '允许',
0 => '不允许'
),0,'是否允许非管理员后台上传文件','此设置仅针对于后台文章编辑有效');
$allowNoneAdminUpload->setAttribute('class', 'j-setting-content j-setting-global');
$form->addInput($allowNoneAdminUpload);
$options = Helper::options();
$alipay = $options->themeUrl('assets/img/donate/alipay.jpg','onecircle');
$wxpay = $options->themeUrl('assets/img/donate/wxpay.jpg','onecircle');
//支付宝二维码
$AlipayPic = new Typecho_Widget_Helper_Form_Element_Text('AlipayPic', NULL, $alipay, '支付宝二维码', '打赏中使用的支付宝二维码,建议尺寸小于250×250,且为正方形');
$AlipayPic->setAttribute('class', 'j-setting-content j-setting-qrcode');
$form->addInput($AlipayPic);
//微信二维码
$WechatPic = new Typecho_Widget_Helper_Form_Element_Text('WechatPic', NULL, $wxpay, '微信二维码', '打赏中使用的微信二维码,建议尺寸小于250×250,且为正方形');
$WechatPic->setAttribute('class', 'j-setting-content j-setting-qrcode');
$form->addInput($WechatPic);
// 资源设置
$enableResource = new Typecho_Widget_Helper_Form_Element_Radio('enableResource',array(
1 => '开启',
0 => '关闭'
),1,'开启资源页','是否开启资源页');
$enableResource->setAttribute('class', 'j-setting-content j-setting-resource');
$form->addInput($enableResource);
$JResourceCatags = new Typecho_Widget_Helper_Form_Element_Textarea(
'JResourceCatags',
null,
'','资源页面展示的分类和tag',
'说明:这里展示分类和 tag 的对应关系,<br>格式:<br>分类1的mid||tag1的mid,tag2的mid<br>比如:1||11,13每行一个'
);
$JResourceCatags->setAttribute('class', 'j-setting-content j-setting-resource');
$form->addInput($JResourceCatags);
$JPageStatus = new Typecho_Widget_Helper_Form_Element_Select(
'JPageStatus',
array('default' => '按钮切换形式(默认)', 'ajax' => '点击加载形式'),
'default',
'选择首页的分页形式',
'介绍:选择一款您所喜欢的分页形式'
);
$JPageStatus->setAttribute('class', 'j-setting-content j-setting-resource');
$form->addInput($JPageStatus->multiMode());
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form)
{
// 添加个人简介字段
$db = Typecho_Db::get();
$user = Typecho_Widget::widget('Widget_User');
$user->execute();
$res = $db->fetchRow($db->select()->from('table.users')->where('uid = ?', $user->uid));
// try{
// $res = $db->fetchRow($db->select('table.users.userSign')->from('table.users')->where('uid = ?', $user->uid));
// $tags = $db->fetchRow($db->select('table.users.userTag')->from('table.users')->where('uid = ?', $user->uid));
//
// }catch (Exception $e){
// $res['userSign'] = '太懒了还没有个性签名';
// $tags['userTag'] = '学生,重庆';
// }
$useravatar = new Typecho_Widget_Helper_Form_Element_Text('userAvatar', NULL, null, '个人头像',
'<div id="avatar-uploader" style="width: 100%;text-align: right;flex-direction: row-reverse;display: none"><div class="row XCHRv" style="width: 100%;display: block"><div id="zz-img-show"></div><div class="zz-add-img "><input id="zz-img-file" type="file" accept="image/*" multiple="multiple"><button id="zz-img-add" type="button"><span class="chevereto-pup-button-icon"><svg class="chevereto-pup-button-icon" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M76.7 87.5c12.8 0 23.3-13.3 23.3-29.4 0-13.6-5.2-25.7-15.4-27.5 0 0-3.5-0.7-5.6 1.7 0 0 0.6 9.4-2.9 12.6 0 0 8.7-32.4-23.7-32.4 -29.3 0-22.5 34.5-22.5 34.5 -5-6.4-0.6-19.6-0.6-19.6 -2.5-2.6-6.1-2.5-6.1-2.5C10.9 25 0 39.1 0 54.6c0 15.5 9.3 32.7 29.3 32.7 2 0 6.4 0 11.7 0V68.5h-13l22-22 22 22H59v18.8C68.6 87.4 76.7 87.5 76.7 87.5z" style="fill: currentcolor;"></path></svg></span><span class="chevereto-pup-button-text">上传</span></button></div></div></div>');
$useravatar->setAttribute("id","personal-userAvatar");
$form->addInput($useravatar);
$userbackimg = new Typecho_Widget_Helper_Form_Element_Text('userBackImg', NULL, null, '背景图片');
$form->addInput($userbackimg);
$sign = new Typecho_Widget_Helper_Form_Element_Text('userSign', NULL, null, '个性签名');
$form->addInput($sign);
$tag = new Typecho_Widget_Helper_Form_Element_Text('userTag', NULL, null, '设置个人TAG,用英文逗号分隔');
$form->addInput($tag);
$sex = new Typecho_Widget_Helper_Form_Element_Radio('userSex',array(
1 => '男',
0 => "女"
),1,"选择性别","");
$form->addInput($sex);
$lifeStatus = new Typecho_Widget_Helper_Form_Element_Radio('userLifeStatus',array(
'' => '保密',
'今日单身' => '今日单身',
'等TA出现' => '等TA出现',
'自由可撩' => '自由可撩',
'心里有人' => '心里有人',
'恋爱中' => '恋爱中',
'一言难尽' => '一言难尽',
),"","情感状态");
$form->addInput($lifeStatus);
//
$useravatar->value($res['userAvatar']);
$userbackimg->value($res["userBackImg"]);
$sign->value($res['userSign']);
$tag->value($res['userTag']);
$sex->value($res['userSex']);
$lifeStatus->value($res['userLifeStatus']);
}
public static function personalConfigHandle($settings,$isSetup){
$db = Typecho_Db::get();
if($isSetup)
{
Typecho_Widget::widget('Widget_Abstract_Options')->insert(array(
'name' => '_plugin:OneCircle',
'value' => serialize($settings),
'user' => 0
));
}
$user = Typecho_Widget::widget('Widget_User');
$user->execute();
$db->query($db->sql()->where('uid = ?', $user->uid)->update('table.users')->rows(array(
'userSign'=>Typecho_Common::removeXSS($settings['userSign']),
'userTag'=>Typecho_Common::removeXSS($settings['userTag']),
'userAvatar'=>Typecho_Common::removeXSS($settings['userAvatar']),
'userBackImg'=>Typecho_Common::removeXSS($settings['userBackImg']),
'userSex'=>Typecho_Common::removeXSS($settings['userSex']),
'userLifeStatus'=>Typecho_Common::removeXSS($settings['userLifeStatus'])
)));
// try{
//
// }catch (Exception $e){
//
// }
return true;
}
public static function zhuce($v)
{
/*获取插件设置*/
$yonghuzu = Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->yonghuzu;
$hasher = new PasswordHash(8, true);
/*判断注册表单是否有密码*/
if (isset(Typecho_Widget::widget('Widget_Register')->request->password)) {
/*将密码设定为用户输入的密码*/
$generatedPassword = Typecho_Widget::widget('Widget_Register')->request->password;
} else {
/*用户没输入密码,随机密码*/
$generatedPassword = Typecho_Common::randString(7);
}
/*将密码设置为常量,方便下个函数adu()直接获取*/
define('passd', $generatedPassword);
/*将密码加密*/
$wPassword = $hasher->HashPassword($generatedPassword);
/*设置用户密码*/
$v['password'] = $wPassword;
/*将注册用户默认用户组改为插件设置的用户组*/
$v['group'] = $yonghuzu;
/*返回注册参数*/
return $v;
}
public static function zhucewan($obj)
{
/*获取密码*/
$wPassword = passd;
/*登录账号*/
$obj->user->login($obj->request->name, $wPassword);
/*删除cookie*/
Typecho_Cookie::delete('__typecho_first_run');
Typecho_Cookie::delete('__typecho_remember_name');
Typecho_Cookie::delete('__typecho_remember_mail');
/*发出提示*/
$obj->widget('Widget_Notice')->set('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $obj->screenName, $wPassword, 'success');
// add default follow circle
OneCircle_Plugin::addDefaultTag($obj->user->uid);
//注册积分
Widget_Common::credits('register');
/*跳转地址(后台)*/
if (NULL != $obj->request->referer) {
$obj->response->redirect($obj->request->referer);
} else if (NULL != $obj->request->tz) {
if (Helper::options()->rewrite == 0) {
$authorurl = Helper::options()->rootUrl . '/index.php/author/';
} else {
$authorurl = Helper::options()->rootUrl . '/author/';
}
$obj->response->redirect($authorurl . $obj->user->uid);
} else {
$obj->response->redirect($obj->options->adminUrl);
}
}
public static function fabu($con, $obj)
{
/*插件用户设置是否勾选*/
if (!empty(Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->tuozhan) && in_array('contributor-nb', Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->tuozhan)) {
/*获取插件设置的分类id*/
//$tcat = Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->tcat;
/*求插件设置的分类id数据与用户勾选的分类数据交集*/
//$result=array_intersect($tcat,$con['category']); && count($result)==0
/*如果用户是贡献者临时给予编辑权限,并且非特例分类*/
if (($obj->have() && $obj->author->group == 'contributor') || $obj->user->group == 'contributor') {
$obj->user->group = 'editor';
}
}
// 给文章发布添加高德地图信息
return $con;
}
public static function fabuwan($con, $obj)
{
// 给文章发布添加高德地图信息
$contents = $obj->request->from('name','district','address');
$db = Typecho_Db::get();
$db->query($db->sql()->where('cid = ?', $obj->cid)->update('table.contents')->rows($contents));
// 发步完文章触发积分机制
Widget_Common::credits('publish',null,$obj->cid);
/** 跳转验证后地址 */
if ($obj->request->referer == 'return') {
exit;
} elseif (NULL != $obj->request->referer) {
/** 发送ping */
$trackback = array_unique(preg_split("/(\r|\n|\r\n)/", trim($obj->request->trackback)));
$obj->widget('Widget_Service')->sendPing($obj->cid, $trackback);
/** 设置提示信息 */
$obj->widget('Widget_Notice')->set('post' == $obj->type ?
_t('文章 "<a href="%s">%s</a>" 已经发布', $obj->permalink, $obj->title):
_t('文章 "%s" 等待审核', $obj->title, 'success'));
/** 设置高亮 */
$obj->widget('Widget_Notice')->highlight($obj->theId);
/** 获取页面偏移 */
$pageQuery = $obj->getPageOffsetQuery($obj->cid);
/** 页面跳转 */
$obj->response->redirect($obj->request->referer);
exit;
} else {
return $con;
}
}
public static function footerjs()
{
if (!empty(Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->tuozhan) && in_array('register-nb', Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->tuozhan)) {
?>
<script>
var OneCirclehtml = '<p><label for="password" class="sr-only">密码</label><input type="password" id="password" name="password" placeholder="输入密码" class="text-l w-100" autocomplete="off" required></p><p><label for="confirm" class="sr-only">确认密码</label><input type="password" id="confirm" name="confirm" placeholder="再次输入密码" class="text-l w-100" autocomplete="off" required></p>';
$("#mail").parent().after(OneCirclehtml);
</script>
<?php
}
}
// SQL创建
// 添加个人简介字段
public static function userSignsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.userSign')->from('table.users');
$db->query($select);
return '检测到个性签名字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userSign` VARCHAR( 255 ) DEFAULT '' COMMENT '用户个性签名';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userSign` VARCHAR( 10 ) DEFAULT ''");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立个性签名字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '个性签名已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('个性签名插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,个性签名插件启用失败。错误号:'.$code);
}
}
// 添加个人标签字段
public static function userTagsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.userTag')->from('table.users');
$db->query($select);
return '检测到个性签名字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userTag` VARCHAR( 255 ) DEFAULT '学生' COMMENT '用户个性标签';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userTag` VARCHAR( 100 ) DEFAULT '学生'");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立个性签名字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '个性签名已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('个性签名插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,个性签名插件启用失败。错误号:'.$code);
}
}
// 添加用户圈子关注
public static function userCircleFollowInstall(){
// create circle follow table
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
if($type == "SQLite"){
$sql ="SELECT count(*) FROM sqlite_master WHERE type='table' AND name='".$prefix."circle_follow';";
$checkTabel = $db->query($sql);
$row = $checkTabel->fetchAll();
if ($row[0]["count(*)"] == '0'){
$res = $db->query('CREATE TABLE `' . $prefix . 'circle_follow` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`uid` bigint(20) NOT NULL DEFAULT 0 ,
`mid` bigint(20) NOT NULL DEFAULT 0 ,
`createtime` int(10) DEFAULT 0
)');
}
}else{
$sql = 'SHOW TABLES LIKE "' . $prefix . 'circle_follow' . '"';
$checkTabel = $db->query($sql);
$row = $checkTabel->fetchAll();
if ('1' == count($row)) {
} else {
$db->query('CREATE TABLE `' . $prefix . 'circle_follow` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uid` bigint(20) NOT NULL DEFAULT 0 COMMENT \'用户ID\',
`mid` bigint(20) NOT NULL DEFAULT 0 COMMENT \'关注meta/circle\',
`createtime` int(10) DEFAULT 0 COMMENT \'关注时间\',
PRIMARY KEY (`id`)
)');
}
}
}
// 添加分类标签
public static function metasTypesqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.metas.tagid')->from('table.metas');
$db->query($select);
return '检测到meta分类字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."metas` ADD `tagid` INTEGER DEFAULT 0 COMMENT 'metas分类';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."metas` ADD `tagid` INTEGER DEFAULT 0");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立meta分类字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return 'meta分类已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('meta分类插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,meta分类插件启用失败。错误号:'.$code);
}
}
// 添加用户头像字段
public static function userAvatarsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.userAvatar')->from('table.users');
$db->query($select);
return '检测到用户头像字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userAvatar` VARCHAR( 512 ) DEFAULT '' COMMENT '用户头像';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userAvatar` VARCHAR( 512 ) DEFAULT ''");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立个性签名字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '个性签名已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('用户头像插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,用户头像插件启用失败。错误号:'.$code);
}
}
// 添加用户背景字段
public static function userBackImgsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.userBackImg')->from('table.users');
$db->query($select);
return '检测到用户背景字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userBackImg` VARCHAR( 512 ) DEFAULT '' COMMENT '用户背景';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userBackImg` VARCHAR( 512 ) DEFAULT ''");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立用户背景字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '用户背景已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('用户背景插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,用户背景插件启用失败。错误号:'.$code);
}
}
// 添加性别字段
public static function userSexsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.userSex','table.users.userLifeStatus')->from('table.users');
$db->query($select);
return '检测到用户性别字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userSex` INT( 1 ) DEFAULT 1 COMMENT '用户性别';");
$db->query("ALTER TABLE `".$prefix."users` ADD `userLifeStatus` VARCHAR( 20 ) DEFAULT '' COMMENT '情感状态';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `userSex` INT( 1 ) DEFAULT 1");
$db->query("ALTER TABLE `".$prefix."users` ADD `userLifeStatus` VARCHAR( 20 ) DEFAULT ''");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立用户性别字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '用户性别已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('用户性别插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,用户性别插件启用失败。错误号:'.$code);
}
}
// 添加用户额外字段
public static function userExtendsqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('table.users.location','table.users.credits','table.users.extend','table.users.level')->from('table.users');
$db->query($select);
return '检测到用户,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `location` VARCHAR( 120 ) DEFAULT '' COMMENT '用户位置';");
$db->query("ALTER TABLE `".$prefix."users` ADD `credits` int(10) unsigned DEFAULT 0 COMMENT '用户信用';");
$db->query("ALTER TABLE `".$prefix."users` ADD `level` int(2) unsigned DEFAULT 1 COMMENT '用户等级';");
$db->query("ALTER TABLE `".$prefix."users` ADD `extend` text COMMENT '用户邀请';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."users` ADD `location` VARCHAR( 120 ) DEFAULT '';");
$db->query("ALTER TABLE `".$prefix."users` ADD `credits` int(10) DEFAULT 0 ;");
$db->query("ALTER TABLE `".$prefix."users` ADD `level` int(2) DEFAULT 1;");
$db->query("ALTER TABLE `".$prefix."users` ADD `extend` text ;");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '插件启用成功';
}
throw new Typecho_Plugin_Exception('插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,插件启用失败。错误号:'.$code);
}
}
// 添加 typecho_creditslog
public static function typecho_TableInstall(){
// create circle follow table
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
if($type == "SQLite"){
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."creditslog` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`uid` int(10) NOT NULL,
`srcId` int(10) NOT NULL,
`created` int(10) NOT NULL DEFAULT '0',
`type` char(16) NOT NULL DEFAULT 'login',
`amount` int(10) NOT NULL DEFAULT '0',
`balance` int(10) NOT NULL DEFAULT '0',
`remark` varchar(255) NOT NULL DEFAULT ''
);");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."onemessages` (
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL ,
`fid` int(10) unsigned NOT NULL ,
`type` char(16) NOT NULL DEFAULT 'message' ,
`text` TEXT NOT NULL ,
`created` int(10) unsigned NOT NULL DEFAULT '0' ,
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (`id`),
KEY `uid` (`uid`)
) ;");
// 删除旧的 message 表
$db->query("DROP TABLE IF EXISTS `" . $prefix ."messages`;");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."notices` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`uid` int(10) NOT NULL ,
`type` char(16) NOT NULL DEFAULT 'comment' ,
`srcId` int(10) NOT NULL DEFAULT '0' ,
`created` int(10) NOT NULL DEFAULT '0' ,
`text` varchar(700) NOT NULL DEFAULT '',
`status` tinyint(1) NOT NULL DEFAULT '0'
);");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."favorites` (
`fid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
`uid` int(10) NOT NULL,
`type` char(16) NOT NULL DEFAULT 'post' ,
`srcId` int(10) NOT NULL DEFAULT '0',
`created` int(10) NOT NULL DEFAULT '0'
);");
}else{
$res= $db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."creditslog` (
`id` int(10) unsigned NOT NULL auto_increment COMMENT '积分日志表主键',
`uid` int(10) unsigned NOT NULL COMMENT '所属用户',
`srcId` int(10) unsigned NOT NULL COMMENT '触发的资源ID',
`created` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`type` char(16) NOT NULL DEFAULT 'login' COMMENT '积分类型',
`amount` int(10) NOT NULL DEFAULT '0' COMMENT '本次积分',
`balance` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '余额',
`remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
PRIMARY KEY (`id`)
);");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."onemessages` (
`id` int(10) unsigned NOT NULL auto_increment COMMENT '消息表主键',
`uid` int(10) unsigned NOT NULL COMMENT '谁的消息',
`fid` int(10) unsigned NOT NULL COMMENT '谁发来的',
`type` char(16) NOT NULL DEFAULT 'message' COMMENT '消息类型',
`text` TEXT NOT NULL COMMENT '消息内容',
`created` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '触发时间',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否已读',
PRIMARY KEY (`id`),
KEY `uid` (`uid`)
) ;");
// 删除旧的 message 表
$db->query("DROP TABLE IF EXISTS `" . $prefix ."messages`;");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."notices` (
`id` int(10) unsigned NOT NULL auto_increment COMMENT '提醒表主键',
`uid` int(10) unsigned NOT NULL COMMENT '提醒的用户',
`type` char(16) NOT NULL DEFAULT 'comment' COMMENT '提醒类型',
`srcId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '触发的资源',
`created` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '触发时间',
`text` varchar(700) NOT NULL DEFAULT '' COMMENT '详情',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否已读',
PRIMARY KEY (`id`),
KEY `uid` (`uid`)
) ;");
$db->query("CREATE TABLE IF NOT EXISTS `" . $prefix ."favorites` (
`fid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '收藏主键',
`uid` int(10) unsigned NOT NULL COMMENT '所属用户',
`type` char(16) NOT NULL DEFAULT 'post' COMMENT '收藏类型',
`srcId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '资源ID',
`created` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '收藏时间',
PRIMARY KEY (`fid`)
);");
}
}
// 添加文章额外字段
public static function contentsSqlInstall()
{
$db = Typecho_Db::get();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
$prefix = $db->getPrefix();
try {
$select = $db->select('name','district ','address')->from('table.contents'); //name : "重庆大学A区", district : "重庆市沙坪坝区",address : "沙坪坝正街174号",
$db->query($select);
return '检测到文章额外字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && (0 == $code ||1054 == $code || $code == '42S22')) ||
('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
try {
if ('Mysql' == $type) {
$db->query("ALTER TABLE `".$prefix."contents` ADD `name` VARCHAR( 30 ) DEFAULT '' COMMENT '地点name';");
$db->query("ALTER TABLE `".$prefix."contents` ADD `district` VARCHAR( 30 ) DEFAULT '' COMMENT '地点区县';");
$db->query("ALTER TABLE `".$prefix."contents` ADD `address` VARCHAR( 40 ) DEFAULT '' COMMENT '街道名称';");
} else if ('SQLite' == $type) {
$db->query("ALTER TABLE `".$prefix."contents` ADD `name` VARCHAR( 30 ) DEFAULT ''");
$db->query("ALTER TABLE `".$prefix."contents` ADD `district` VARCHAR( 30 ) DEFAULT ''");
$db->query("ALTER TABLE `".$prefix."contents` ADD `address` VARCHAR( 40 ) DEFAULT ''");
} else {
throw new Typecho_Plugin_Exception('不支持的数据库类型:'.$type);
}
return '建立文章额外字段,插件启用成功';
} catch (Typecho_Db_Exception $e) {
$code = $e->getCode();
if(('Mysql' == $type && 1060 == $code) ) {
return '文章额外字段已经存在,插件启用成功';
}
throw new Typecho_Plugin_Exception('文章额外字段插件启用失败。错误号:'.$code);
}
}
throw new Typecho_Plugin_Exception('数据表检测失败,文章额外字段插件启用失败。错误号:'.$code);
}
}
// add default faned tag , 用户注册的时候添加默认关注
public static function addDefaultTag($uid){
$db = Typecho_Db::get();
$umid = Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->registeruserMid;
$insert = $db->insert('table.circle_follow')
->rows(array('uid' => $uid, 'mid' => $umid));
$db->query($insert);
}
// 添加新的 Page
public static function handleInit($archive,$select){
// $fp = fopen('write.txt', 'a+b'); //a+读写方式打开,将文件指针指向文件末尾。b为强制使用二进制模式. 如果文件不存在则尝试创建之。
// fwrite($fp,print_r($archive->parameter->type."--\r\n",true));
// fwrite($fp,print_r(Helper::options()->JIndexShowPage."--\r\n",true));
// fclose($fp); //关闭打开的文件。
}
public static function handle($type,$archive,$select){
if ($type == 'metas'){
Widget_Metasmanage::handle($archive);
}elseif ($type == 'neighbor' or $type == 'neighbor_page'){
Widget_Neighbor::handle($archive,$select);
}elseif ($type == 'myblog' or $type == 'myblog_page'){
Widget_blog::handle($archive,$select);
}elseif ($type == 'setting'){
Widget_usercenter::handleSetting($archive,$select);
}elseif ($type == 'credits'){
Widget_usercenter::handleCredits($archive,$select);
}elseif ($type == 'notice'){
Widget_notices::noticeHandle($archive, $select);
}elseif ($type == 'messages'){
Widget_messages::messageHandle($archive, $select);
}elseif($type == 'resources' or $type == 'resources_page'){
Widget_CustomHandler::handleResourcesPage($archive, $select);
}elseif($type == 'hotposts' or $type == 'hotposts_page'){
Widget_CustomHandler::handleHotPostsPage($archive, $select);
}
return true; // 不输出文章 // 查看源码
}
// end
// 重写 typecho 后台上传
public static function uploadHandle($file)
{
$user = Typecho_Widget::widget('Widget_User');
$user->execute();
$allowNoneAdminUpload = Typecho_Widget::widget('Widget_Options')->plugin('OneCircle')->allowNoneAdminUpload;
$upload = new Widget_Upload_Extend();