Changeset 3313464
- Timestamp:
- 06/17/2025 06:34:22 PM (8 months ago)
- Location:
- simple-baseball-scoreboard
- Files:
-
- 5 added
- 2 edited
-
tags/2.0 (added)
-
tags/2.0/js (added)
-
tags/2.0/js/ytmr_simple_baseball_scoreboard.js (added)
-
tags/2.0/readme.txt (added)
-
tags/2.0/ytmr_simple_baseball_scoreboard.php (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/ytmr_simple_baseball_scoreboard.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-baseball-scoreboard/trunk/readme.txt
r3018402 r3313464 4 4 Tags: baseball, score, scoreboard 5 5 Requires at least: 4.8.1 6 Tested up to: 6. 4.27 Stable tag: 1.36 Tested up to: 6.8.1 7 Stable tag: 2.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 34 34 == ChangeLog == 35 35 36 = Version 2.0 = 37 38 * Security update 39 36 40 = Version 1.3 = 37 41 -
simple-baseball-scoreboard/trunk/ytmr_simple_baseball_scoreboard.php
r1725296 r3313464 2 2 /* 3 3 Plugin Name: Simple Baseball Score Board 4 Plugin URI: https:// php.dogrow.net/wordpressplugin/simple-baseball-scoreboard/4 Plugin URI: https://www.dogrow.net/php/wordpressplugin/simple-baseball-scoreboard/ 5 5 Description: Generate baseball scoreboard from shortcode 6 Version: 1.36 Version: 2.0 7 7 Author: DOGROW.NET 8 Author https://php.dogrow.net/9 8 License: GPL2 10 9 */ … … 32 31 add_action('admin_head', array($this,'proc_output_css'), 9999); 33 32 //------------------------------------------------------------------ 34 add_shortcode(' ytmr_bb_scoreboard', array($this, 'proc_shortcode'));33 add_shortcode('bb_scoreboard', array($this, 'proc_shortcode')); 35 34 add_filter('widget_text', 'do_shortcode'); 36 35 //------------------------------------------------------------------ … … 73 72 border-width: {$ary_set['border_line_width']['v']}; 74 73 border-style: solid; 75 margin: 3px; padding: 3px; 74 margin: 0.5rem; padding: 0.5rem; 75 width: fit-content; 76 76 } 77 77 div#YTMRBBScoreBoard table{ … … 80 80 margin:0 !important; 81 81 padding:0 !important; 82 width: auto; 82 83 } 83 84 div#YTMRBBScoreBoard tr, … … 89 90 text-align: center; 90 91 line-height: 1.5; 91 padding: 4px;92 padding: 0.15rem; 92 93 color: {$ary_set['text_color']['v']}; 94 white-space: nowrap; 93 95 } 94 96 div#YTMRBBScoreBoard div.inner{ 95 padding: 4px 2px;97 padding: 0.5rem; 96 98 background-color: {$ary_set['box_color']['v']}; 97 99 } … … 102 104 } 103 105 ////////////////////////////////////////////////////////////////////// 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 104 111 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"> 152 div#YTMRBBScoreBoard .{$table_class} td{ 153 {$size_css} 154 } 155 </style> 156 <div id="YTMRBBScoreBoard"><table class="{$table_class}">{$html}</table></div> 157 EOM; 158 159 return $str; 160 } 161 function proc_create_menu() { 109 162 add_submenu_page('options-general.php', 'Simple BBScoreboard', 'Simple BBScoreboard', 'administrator', __FILE__, array($this, 'proc_display_settings_page')); 110 163 } … … 131 184 $ary_bw_sel = array('1px'=>'', '2px'=>'', '3px'=>''); 132 185 $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 //------------------------------------------------------------------137 186 echo <<< EOM 138 187 <div class="wrap"> 139 188 <h2>Simple Baseball Scoreboard</h2> 140 189 <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> 142 191 <p>Parameters : <br /> 143 192 - fsize : font size [rem]<br /> … … 146 195 - scr1, scr2 : run of the inning (separator is "/")<br /> 147 196 </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"> 200 div#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 150 211 <h2 style="margin-top:2.5rem">2. Settings</h2> 151 212 <form id="YTMRBBScoreBoard_form" method="post" action="options.php"> … … 155 216 echo <<< EOM 156 217 <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> 157 242 <tr> 158 243 <th>{$ary_set['border_line_width']['t']}</th> … … 165 250 </td> 166 251 </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>191 252 </table> 192 253 EOM; … … 197 258 EOM; 198 259 } 199 //////////////////////////////////////////////////////////////////////200 // args['fsize'] : text size [rem]201 // args['width'] : whole width202 // args['tm1'] : team name #1203 // args['tm2'] : team name #2204 // args['scr1'] : score #1 , separator='/' ex) 0/0/1/0/0/1205 // args['scr2'] : score #2206 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 innings226 $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 score233 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 <<< EOM242 <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 }253 260 } // end of class 254 261 ?>
Note: See TracChangeset
for help on using the changeset viewer.