Plugin Directory

Changeset 3313464


Ignore:
Timestamp:
06/17/2025 06:34:22 PM (8 months ago)
Author:
dogrow
Message:

Security updated
Tested up to: 6.8.1

Location:
simple-baseball-scoreboard
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • simple-baseball-scoreboard/trunk/readme.txt

    r3018402 r3313464  
    44Tags: baseball, score, scoreboard
    55Requires at least: 4.8.1
    6 Tested up to: 6.4.2
    7 Stable tag: 1.3
     6Tested up to: 6.8.1
     7Stable tag: 2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3434== ChangeLog ==
    3535
     36= Version 2.0 =
     37
     38* Security update
     39
    3640= Version 1.3 =
    3741
  • simple-baseball-scoreboard/trunk/ytmr_simple_baseball_scoreboard.php

    r1725296 r3313464  
    22/*
    33Plugin Name: Simple Baseball Score Board
    4 Plugin URI: https://php.dogrow.net/wordpressplugin/simple-baseball-scoreboard/
     4Plugin URI: https://www.dogrow.net/php/wordpressplugin/simple-baseball-scoreboard/
    55Description: Generate baseball scoreboard from shortcode
    6 Version: 1.3
     6Version: 2.0
    77Author: DOGROW.NET
    8 Author https://php.dogrow.net/
    98License: GPL2
    109*/
     
    3231    add_action('admin_head', array($this,'proc_output_css'), 9999);
    3332    //------------------------------------------------------------------
    34     add_shortcode('ytmr_bb_scoreboard', array($this, 'proc_shortcode'));
     33    add_shortcode('bb_scoreboard', array($this, 'proc_shortcode'));
    3534    add_filter('widget_text', 'do_shortcode');
    3635    //------------------------------------------------------------------
     
    7372  border-width: {$ary_set['border_line_width']['v']};
    7473  border-style: solid;
    75   margin: 3px; padding: 3px;
     74  margin: 0.5rem; padding: 0.5rem;
     75  width: fit-content;
    7676}
    7777div#YTMRBBScoreBoard table{
     
    8080  margin:0 !important;
    8181  padding:0 !important;
     82  width: auto;
    8283}
    8384div#YTMRBBScoreBoard tr,
     
    8990  text-align: center;
    9091  line-height: 1.5;
    91   padding: 4px;
     92  padding: 0.15rem;
    9293  color: {$ary_set['text_color']['v']};
     94  white-space: nowrap;
    9395}
    9496div#YTMRBBScoreBoard div.inner{
    95   padding: 4px 2px;
     97  padding: 0.5rem;
    9698  background-color: {$ary_set['box_color']['v']};
    9799}
     
    102104  }
    103105  //////////////////////////////////////////////////////////////////////
     106  // args['fsize'] : text size [rem]
     107  // args['tm1']  : team name #1
     108  // args['tm2']  : team name #2
     109  // args['scr1'] : score #1 , separator='/'  ex) 0/0/1/0/0/1
     110  // args['scr2'] : score #2
    104111  public function proc_shortcode( $args ){
    105     return $this->sub_display_table($args);
    106   }
    107   //////////////////////////////////////////////////////////////////////
    108   public function proc_create_menu() {
     112    // --- Sanitize shortcode attributes ---------------------------------
     113    $fsize = ( isset( $args['fsize'] ) && is_numeric( $args['fsize'] ) )
     114           ? floatval( $args['fsize'] )
     115           : '';
     116    $tm1   = isset( $args['tm1'] ) ? $args['tm1'] : 'team1';
     117    $tm2   = isset( $args['tm2'] ) ? $args['tm2'] : 'team2';
     118
     119    // Build style string safely
     120    $size_css = ( $fsize !== '' ) ? 'font-size:' . $fsize . 'rem !important;' : '';
     121    $table_class = 'tc_' . str_replace( '.', '_', isset( $args['fsize'] ) ? sanitize_key( $args['fsize'] ) : '' );
     122
     123    // Escape team names for HTML
     124    $ary_tm = array( esc_html( $tm1 ), esc_html( $tm2 ) );
     125
     126    // Force score values to integers to avoid XSS
     127    $scr1_raw = isset( $args['scr1'] ) ? explode( '/', $args['scr1'] ) : array();
     128    $scr2_raw = isset( $args['scr2'] ) ? explode( '/', $args['scr2'] ) : array();
     129    $ary_scr  = array( array_map( 'intval', $scr1_raw ), array_map( 'intval', $scr2_raw ) );
     130
     131    $nScr = max( count( $ary_scr[0] ), count( $ary_scr[1] ) );
     132
     133    // -------------------- Build Scoreboard HTML ------------------------
     134    $html  = '<tr><td></td>';
     135    for ( $i = 1; $i <= $nScr; $i++ ) {
     136        $html .= '<td>' . $i . '</td>';
     137    }
     138    $html .= '<td>R</td></tr>';
     139
     140    foreach ( $ary_scr as $idx => $scr ) {
     141        $html .= '<tr><td><div class="inner">' . $ary_tm[ $idx ] . '</div></td>';
     142        for ( $i = 0; $i < $nScr; $i++ ) {
     143            $val = isset( $scr[ $i ] ) ? intval( $scr[ $i ] ) : '';
     144            $html .= '<td><div class="inner">' . $val . '</div></td>';
     145        }
     146        $html .= '<td><div class="inner">' . array_sum( $scr ) . '</div></td></tr>';
     147    }
     148
     149    // ----------------------- Final Output ------------------------------
     150    $str = <<<EOM
     151<style type="text/css">
     152div#YTMRBBScoreBoard .{$table_class} td{
     153  {$size_css}
     154}
     155</style>
     156<div id="YTMRBBScoreBoard"><table class="{$table_class}">{$html}</table></div>
     157EOM;
     158
     159    return $str;
     160}
     161function proc_create_menu() {
    109162    add_submenu_page('options-general.php', 'Simple BBScoreboard', 'Simple BBScoreboard', 'administrator', __FILE__, array($this, 'proc_display_settings_page'));
    110163  }
     
    131184    $ary_bw_sel = array('1px'=>'', '2px'=>'', '3px'=>'');
    132185    $ary_bw_sel[$ary_set['border_line_width']['v']] = 'selected';
    133     //------------------------------------------------------------------
    134     $args = array('fsize'=>'1.2', 'width'=>'600px', 'tm1'=>'GreenSox', 'tm2'=>'Monkeys', 'scr1'=>'0/0/1/1/0/3/0', 'scr2'=>'1/0/0/2/2/1/X');
    135     $html_scrboard = $this->sub_display_table($args);
    136     //------------------------------------------------------------------
    137186echo <<< EOM
    138187<div class="wrap">
    139188<h2>Simple Baseball Scoreboard</h2>
    140189<h2>1. Usage</h2>
    141 <p>Short code : <span style="background:#fff;color:#00f;padding:3px 5px;font-size:1.2rem">[ytmr_bb_scoreboard]</span></p>
     190<p>Short code : <span style="background:#fff;color:#00f;padding:3px 5px;font-size:1.2rem">[bb_scoreboard fsize=N tm1=NAME tm2=NAME scr1=RUN scr2=RUN]</span></p>
    142191<p>Parameters : <br />
    143192- fsize : font size [rem]<br />
     
    146195- scr1, scr2 : run of the inning (separator is "/")<br />
    147196</p>
    148 <p>sample : <span style="background:#fff;color:#00f;padding:3px 5px;font-size:1.2rem">[ytmr_bb_scoreboard fsize="1.2" width="600px" tm1="GreenSox" tm2="Monkeys" scr1="0/0/1/1/0/3/0" scr2="1/0/0/2/2/1/X"]</span></p>
    149 {$html_scrboard}
     197<p>sample : <span style="background:#fff;color:#00f;padding:3px 5px;font-size:1.2rem">[bb_scoreboard fsize="1.2" tm1="GreenSox" tm2="Monkeys" scr1="0/0/1/1/0/3/0" scr2="1/0/0/2/2/1/X"]</span></p>
     198
     199<style type="text/css">
     200div#YTMRBBScoreBoard td{
     201  font-size: 1.2rem;
     202</style>
     203<div id="YTMRBBScoreBoard" style="width:30rem;max-width:100%">
     204  <table style="width:100%">
     205    <tr><td></td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>R</td></tr>
     206    <tr><td><div class="inner">GreenSox</div></td><td><div class="inner">0</div></td><td><div class="inner">0</div></td><td><div class="inner">1</div></td><td><div class="inner">1</div></td><td><div class="inner">0</div></td><td><div class="inner">3</div></td><td><div class="inner">0</div></td><td><div class="inner">5</div></td></tr>
     207    <tr><td><div class="inner">Monkeys</div></td> <td><div class="inner">1</div></td><td><div class="inner">0</div></td><td><div class="inner">0</div></td><td><div class="inner">2</div></td><td><div class="inner">2</div></td><td><div class="inner">1</div></td><td><div class="inner">X</div></td><td><div class="inner">6</div></td></tr>
     208  </table>
     209</div>
     210
    150211<h2 style="margin-top:2.5rem">2. Settings</h2>
    151212<form id="YTMRBBScoreBoard_form" method="post" action="options.php">
     
    155216echo <<< EOM
    156217  <table class="form-table">
     218    <tr>
     219      <th>{$ary_set['border_line_color']['t']}</th>
     220      <td>
     221        <input type="color" name="{$this->m_option_name}[border_line_color][v]" value="{$ary_set['border_line_color']['v']}">
     222      </td>
     223    </tr>
     224    <tr>
     225      <th>{$ary_set['text_color']['t']}</th>
     226      <td>
     227        <input type="color" name="{$this->m_option_name}[text_color][v]" value="{$ary_set['text_color']['v']}">
     228      </td>
     229    </tr>
     230    <tr>
     231      <th>{$ary_set['box_color']['t']}</th>
     232      <td>
     233        <input type="color" name="{$this->m_option_name}[box_color][v]" value="{$ary_set['box_color']['v']}">
     234      </td>
     235    </tr>
     236    <tr>
     237      <th>{$ary_set['background_color']['t']}</th>
     238      <td>
     239        <input type="color" name="{$this->m_option_name}[background_color][v]" value="{$ary_set['background_color']['v']}">
     240      </td>
     241    </tr>
    157242    <tr>
    158243      <th>{$ary_set['border_line_width']['t']}</th>
     
    165250      </td>
    166251    </tr>
    167     <tr>
    168       <th>{$ary_set['border_line_color']['t']}</th>
    169       <td>
    170         <input type="color" name="{$this->m_option_name}[border_line_color][v]" value="{$ary_set['border_line_color']['v']}">
    171       </td>
    172     </tr>
    173     <tr>
    174       <th>{$ary_set['background_color']['t']}</th>
    175       <td>
    176         <input type="color" name="{$this->m_option_name}[background_color][v]" value="{$ary_set['background_color']['v']}">
    177       </td>
    178     </tr>
    179     <tr>
    180       <th>{$ary_set['box_color']['t']}</th>
    181       <td>
    182         <input type="color" name="{$this->m_option_name}[box_color][v]" value="{$ary_set['box_color']['v']}">
    183       </td>
    184     </tr>
    185     <tr>
    186       <th>{$ary_set['text_color']['t']}</th>
    187       <td>
    188         <input type="color" name="{$this->m_option_name}[text_color][v]" value="{$ary_set['text_color']['v']}">
    189       </td>
    190     </tr>
    191252  </table>
    192253EOM;
     
    197258EOM;
    198259  }
    199   //////////////////////////////////////////////////////////////////////
    200   // args['fsize'] : text size [rem]
    201   // args['width'] : whole width
    202   // args['tm1']  : team name #1
    203   // args['tm2']  : team name #2
    204   // args['scr1'] : score #1 , separator='/'  ex) 0/0/1/0/0/1
    205   // args['scr2'] : score #2
    206   public function sub_display_table($args){
    207     $fsize = (isset($args['fsize']))? $args['fsize'] : '1';
    208     $tm1   = (isset($args['tm1']))? $args['tm1'] : 'team1';
    209     $tm2   = (isset($args['tm2']))? $args['tm2'] : 'team2';
    210     $width = (isset($args['width']))? $args['width'] : '100%';
    211     //------------------------------------------------------------------
    212     $html = "";
    213     $size = 'font-size:'.$fsize.'rem !important;';
    214     $table_class = 'tc_'.str_replace('.','_',$args['fsize']);
    215     //------------------------------------------------------------------
    216     $ary_tm = array();
    217     $ary_tm[] = $tm1;
    218     $ary_tm[] = $tm2;
    219     //------------------------------------------------------------------
    220     $ary_scr = array();
    221     $ary_scr[] = explode('/', $args['scr1']);
    222     $ary_scr[] = explode('/', $args['scr2']);
    223     $nScr = max(count($ary_scr[0]), count($ary_scr[1]));
    224     //------------------------------------------------------------------
    225     // display innings
    226     $html .= '<tr><td></td>';
    227     for($i=1 ; $i <= $nScr ; $i++){
    228       $html .= '<td>'.$i.'</td>';
    229     }
    230     $html .= '<td>R</td></tr>';
    231     //------------------------------------------------------------------
    232     // display score
    233     foreach($ary_scr as $idx => $scr){
    234       $html .= '<tr><td><div class="inner">'.$ary_tm[$idx].'</div></td>';
    235       for($i=0 ; $i < $nScr ; $i++){
    236         $html .= '<td><div class="inner">'.$scr[$i].'</div></td>';
    237       }
    238       $html .= '<td><div class="inner">'.array_sum($scr).'</div></td></tr>';
    239     }
    240     //------------------------------------------------------------------
    241 return <<< EOM
    242 <style type="text/css">
    243 div#YTMRBBScoreBoard{
    244   max-width: 100% !important;
    245 }
    246 div#YTMRBBScoreBoard .{$table_class} td{
    247   {$size}
    248 }
    249 </style>
    250 <div id="YTMRBBScoreBoard" style="width: {$width} !important"><table class="{$table_class}" style="width:100%">{$html}</table></div>
    251 EOM;
    252   }
    253260}     // end of class
    254261?>
Note: See TracChangeset for help on using the changeset viewer.