Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.79 KB | None | 0 0
  1. #============================================================================================================
  2. #
  3. #       拡張機能 - threadattr
  4. #       0ch_threadattr.pl
  5. #
  6. #============================================================================================================
  7. package ZPL_threadattr;
  8.  
  9.  
  10.  
  11. #------------------------------------------------------------------------------------------------------------
  12. #       拡張機能名称取得
  13. #------------------------------------------------------------------------------------------------------------
  14. sub getName
  15. {
  16.         return 'スレッドに属性付加';
  17. }
  18.  
  19. #------------------------------------------------------------------------------------------------------------
  20. #       拡張機能説明取得
  21. #------------------------------------------------------------------------------------------------------------
  22. sub getExplanation
  23. {
  24.         return 'スレッドに属性を付加するサンプルプラグインです。';
  25. }
  26.  
  27. #------------------------------------------------------------------------------------------------------------
  28. #       拡張機能タイプ取得
  29. #------------------------------------------------------------------------------------------------------------
  30. sub getType
  31. {
  32.         return 16;
  33. }
  34.  
  35. #------------------------------------------------------------------------------------------------------------
  36. #       設定リスト取得 (0ch+ Only)
  37. #------------------------------------------------------------------------------------------------------------
  38. sub getConfig
  39. {
  40.         return {};
  41. }
  42.  
  43. #------------------------------------------------------------------------------------------------------------
  44. #       拡張機能実行インタフェイス
  45. #------------------------------------------------------------------------------------------------------------
  46. sub execute
  47. {
  48.         my $this = shift;
  49.         my ($Sys, $Form, $type) = @_;
  50.  
  51.         # 0ch本家では実行しない
  52.         return 0 if (!$this->{'is0ch+'});
  53.  
  54.         my $CGI = $Sys->Get('MainCGI');
  55.  
  56.         # baggins.pl BILBO : subjectの管理が主、属性情報の管理も兼ねる
  57.         my $Threads = $CGI->{'THREADS'} || $Sys->Get('_THREAD_');
  58.  
  59.         # 対象スレッドの番号
  60.         my $threadid = $Sys->Get('KEY');
  61.  
  62.         # 属性情報を扱うには一度でも読み込む必要がある
  63.         $Threads->LoadAttr($Sys);
  64.  
  65.         # ここで属性操作
  66.         if ($Sys->Equal('MODE', 1)) {
  67.                 # >>1 スレ立て
  68.  
  69.                 my $mail = $Form->Get('mail');
  70.                 # メール欄に !myattr があれば消しつつ属性を設定
  71.                 if ($mail =~ s/!suko//g) {
  72.                         $Form->Set('mail', $mail);
  73.  
  74.                         # 属性を設定
  75.                         $Threads->SetAttr($threadid, 'myattr', 1);
  76.                         # 属性を変更したら保存
  77.                         $Threads->SaveAttr($Sys);
  78.  
  79.                 my $text = $Form->Get('MESSAGE');
  80.                 $text .= "<hr><b>くこはシャワーズちゃんのおうち</b>";
  81.                 $Form->Set('MESSAGE', $text);
  82.  
  83.                 }
  84.         } else {
  85.                 # >>2- レス
  86.  
  87.                 my $mail = $Form->Get('mail');
  88.                 # メール欄に !no-myattr があれば消しつつ属性を削除
  89.                 if ($mail =~ s/!sukoranai//g) {
  90.                         $Form->Set('mail', $mail);
  91.  
  92.                         # 属性を削除
  93.                         $Threads->DeleteAttr($threadid, 'myattr');
  94.                         # 属性を変更したら保存
  95.                         $Threads->SaveAttr($Sys);
  96.  
  97.                         my $text = $Form->Get('MESSAGE');
  98.                         $text .= "<hr><b>【注意】ID表示が有効になりました</b>";
  99.                         $Form->Set('MESSAGE', $text);
  100.  
  101.                 }
  102.         }
  103.  
  104.         # 属性を取得、属性情報がなければ空文字列
  105.         my $myattr = $Threads->GetAttr($threadid, 'myattr');
  106.  
  107.         # 属性がある場合の処理
  108.         if ($myattr) {
  109.                 #my $text = $Form->Get('MESSAGE');
  110.                 #$text .= "<hr>myattr属性あり";
  111.                 #$Form->Set('MESSAGE', $text);
  112.  
  113.                 my $id = "???";
  114.  
  115.                 ### idpart(ID)を設定
  116.                 $Form->Set('idpart', "ID:$id");
  117.  
  118.         }
  119.  
  120.         my $attr = $Threads->{'ATTR'}->{$threadid};
  121.         my $attrstr = '';
  122.         foreach my $key (keys %$attr) {
  123.                 $attrstr .= "$key=$attr->{$key}<br>";
  124.         }
  125.         #my $text = $Form->Get('MESSAGE');
  126.         #$Form->Set('MESSAGE', "$text<hr>$attrstr");
  127.  
  128.         return 0;
  129. }
  130.  
  131.  
  132.  
  133. #------------------------------------------------------------------------------------------------------------
  134. #       コンストラクタ
  135. #------------------------------------------------------------------------------------------------------------
  136. sub new
  137. {
  138.         my $class = shift;
  139.         my ($Config) = @_;
  140.  
  141.         my $this = {};
  142.         bless $this, $class;
  143.  
  144.         if (defined $Config) {
  145.                 $this->{'PLUGINCONF'} = $Config;
  146.                 $this->{'is0ch+'} = 1;
  147.         }
  148.         else {
  149.                 $this->{'CONFIG'} = $class->getConfig();
  150.                 $this->{'is0ch+'} = 0;
  151.         }
  152.  
  153.         return $this;
  154. }
  155.  
  156. #------------------------------------------------------------------------------------------------------------
  157. #       設定値取得 (0ch+ Only)
  158. #------------------------------------------------------------------------------------------------------------
  159. sub GetConf
  160. {
  161.         my $this = shift;
  162.         my ($key) = @_;
  163.         if ($this->{'is0ch+'}) {
  164.                 return $this->{'PLUGINCONF'}->GetConfig($key);
  165.         }
  166.         elsif (defined $this->{'CONFIG'}->{$key}) {
  167.                 return $this->{'CONFIG'}->{$key}->{'default'};
  168.         }
  169. }
  170.  
  171. #------------------------------------------------------------------------------------------------------------
  172. #       設定値設定 (0ch+ Only)
  173. #------------------------------------------------------------------------------------------------------------
  174. sub SetConf
  175. {
  176.         my $this = shift;
  177.         my ($key, $val) = @_;
  178.         if ($this->{'is0ch+'}) {
  179.                 $this->{'PLUGINCONF'}->SetConfig($key, $val);
  180.         }
  181.         elsif (defined $this->{'CONFIG'}->{$key}) {
  182.                 $this->{'CONFIG'}->{$key}->{'default'} = $val;
  183.         }
  184.         else {
  185.                 $this->{'CONFIG'}->{$key} = { 'default' => $val };
  186.         }
  187. }
  188.  
  189. #============================================================================================================
  190. #       Module END
  191. #============================================================================================================
  192. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement