Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #============================================================================================================
- #
- # 拡張機能 - threadattr
- # 0ch_threadattr.pl
- #
- #============================================================================================================
- package ZPL_threadattr;
- #------------------------------------------------------------------------------------------------------------
- # 拡張機能名称取得
- #------------------------------------------------------------------------------------------------------------
- sub getName
- {
- return 'スレッドに属性付加';
- }
- #------------------------------------------------------------------------------------------------------------
- # 拡張機能説明取得
- #------------------------------------------------------------------------------------------------------------
- sub getExplanation
- {
- return 'スレッドに属性を付加するサンプルプラグインです。';
- }
- #------------------------------------------------------------------------------------------------------------
- # 拡張機能タイプ取得
- #------------------------------------------------------------------------------------------------------------
- sub getType
- {
- return 16;
- }
- #------------------------------------------------------------------------------------------------------------
- # 設定リスト取得 (0ch+ Only)
- #------------------------------------------------------------------------------------------------------------
- sub getConfig
- {
- return {};
- }
- #------------------------------------------------------------------------------------------------------------
- # 拡張機能実行インタフェイス
- #------------------------------------------------------------------------------------------------------------
- sub execute
- {
- my $this = shift;
- my ($Sys, $Form, $type) = @_;
- # 0ch本家では実行しない
- return 0 if (!$this->{'is0ch+'});
- my $CGI = $Sys->Get('MainCGI');
- # baggins.pl BILBO : subjectの管理が主、属性情報の管理も兼ねる
- my $Threads = $CGI->{'THREADS'} || $Sys->Get('_THREAD_');
- # 対象スレッドの番号
- my $threadid = $Sys->Get('KEY');
- # 属性情報を扱うには一度でも読み込む必要がある
- $Threads->LoadAttr($Sys);
- # ここで属性操作
- if ($Sys->Equal('MODE', 1)) {
- # >>1 スレ立て
- my $mail = $Form->Get('mail');
- # メール欄に !myattr があれば消しつつ属性を設定
- if ($mail =~ s/!suko//g) {
- $Form->Set('mail', $mail);
- # 属性を設定
- $Threads->SetAttr($threadid, 'myattr', 1);
- # 属性を変更したら保存
- $Threads->SaveAttr($Sys);
- my $text = $Form->Get('MESSAGE');
- $text .= "<hr><b>くこはシャワーズちゃんのおうち</b>";
- $Form->Set('MESSAGE', $text);
- }
- } else {
- # >>2- レス
- my $mail = $Form->Get('mail');
- # メール欄に !no-myattr があれば消しつつ属性を削除
- if ($mail =~ s/!sukoranai//g) {
- $Form->Set('mail', $mail);
- # 属性を削除
- $Threads->DeleteAttr($threadid, 'myattr');
- # 属性を変更したら保存
- $Threads->SaveAttr($Sys);
- my $text = $Form->Get('MESSAGE');
- $text .= "<hr><b>【注意】ID表示が有効になりました</b>";
- $Form->Set('MESSAGE', $text);
- }
- }
- # 属性を取得、属性情報がなければ空文字列
- my $myattr = $Threads->GetAttr($threadid, 'myattr');
- # 属性がある場合の処理
- if ($myattr) {
- #my $text = $Form->Get('MESSAGE');
- #$text .= "<hr>myattr属性あり";
- #$Form->Set('MESSAGE', $text);
- my $id = "???";
- ### idpart(ID)を設定
- $Form->Set('idpart', "ID:$id");
- }
- my $attr = $Threads->{'ATTR'}->{$threadid};
- my $attrstr = '';
- foreach my $key (keys %$attr) {
- $attrstr .= "$key=$attr->{$key}<br>";
- }
- #my $text = $Form->Get('MESSAGE');
- #$Form->Set('MESSAGE', "$text<hr>$attrstr");
- return 0;
- }
- #------------------------------------------------------------------------------------------------------------
- # コンストラクタ
- #------------------------------------------------------------------------------------------------------------
- sub new
- {
- my $class = shift;
- my ($Config) = @_;
- my $this = {};
- bless $this, $class;
- if (defined $Config) {
- $this->{'PLUGINCONF'} = $Config;
- $this->{'is0ch+'} = 1;
- }
- else {
- $this->{'CONFIG'} = $class->getConfig();
- $this->{'is0ch+'} = 0;
- }
- return $this;
- }
- #------------------------------------------------------------------------------------------------------------
- # 設定値取得 (0ch+ Only)
- #------------------------------------------------------------------------------------------------------------
- sub GetConf
- {
- my $this = shift;
- my ($key) = @_;
- if ($this->{'is0ch+'}) {
- return $this->{'PLUGINCONF'}->GetConfig($key);
- }
- elsif (defined $this->{'CONFIG'}->{$key}) {
- return $this->{'CONFIG'}->{$key}->{'default'};
- }
- }
- #------------------------------------------------------------------------------------------------------------
- # 設定値設定 (0ch+ Only)
- #------------------------------------------------------------------------------------------------------------
- sub SetConf
- {
- my $this = shift;
- my ($key, $val) = @_;
- if ($this->{'is0ch+'}) {
- $this->{'PLUGINCONF'}->SetConfig($key, $val);
- }
- elsif (defined $this->{'CONFIG'}->{$key}) {
- $this->{'CONFIG'}->{$key}->{'default'} = $val;
- }
- else {
- $this->{'CONFIG'}->{$key} = { 'default' => $val };
- }
- }
- #============================================================================================================
- # Module END
- #============================================================================================================
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement