Plugin Directory

Changeset 1071883


Ignore:
Timestamp:
01/20/2015 07:20:46 PM (11 years ago)
Author:
vEnCa-X
Message:

v 0.0.3

Location:
nastrikejcz/trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • nastrikejcz/trunk/nastrikej.php

    r973504 r1071883  
    55  Plugin URI: http://www.nastrikej.cz
    66  Description: Rozpis hasičských soutěží/výsledků z celé ČR
    7   Version: 0.2
     7  Version: 0.3
    88  Author: vEnCa-X
    99  Author URI: http://www.venca-x.cz
     
    1111 */
    1212
    13 class Nastrikej extends WP_Widget
     13define("URL", "http://www.nastrikej.cz/json/");
     14   
     15class NastrikejCompetitions extends WP_Widget
    1416{
    1517
    16     protected $url = "http://www.nastrikej.cz/json/";
    17 
    1818    public function __construct()
    1919    {
    20         parent::__construct( false, $name = __( 'Nastříkej' ) );
     20        parent::__construct( false, $name = __( 'Nastříkej - soutěže' ) );
    2121    }
    2222
    2323    public function form( $instance )
    2424    {
    25         $instance = wp_parse_args(
    26                 (array) $instance
    27         );
    28 
    29         if ( !empty( $instance['title'] ) )
     25        $instance = wp_parse_args( (array) $instance );
     26
     27        if ( isset( $instance['title'] ) )
    3028        {
    3129            $title = $instance['title'];
     
    3533            $title = __( 'Soutěže', 'wptuts-countdowner-locale' );
    3634        }
     35
     36        if ( isset( $instance['seasonId'] ) )
     37        {
     38            $seasonId = $instance['seasonId'];
     39        }
     40        else
     41        {
     42            $seasonId = "";
     43        }
    3744       
    38         if ( !empty( $instance['seasonId'] ) )
    39         {
    40             $seasonId = $instance['seasonId'];
    41         }
    42         else
    43         {
    44             $seasonId = "";
    45         }
    46        
    47         if ( !empty( $instance['teamsId'] ) )
     45        if ( isset( $instance['teamsId'] ) )
    4846        {
    4947            $teamsId = $instance['teamsId'];
     
    5553
    5654        // Display the admin form
    57         include( plugin_dir_path( __FILE__ ) . '/views/admin.php' );
     55        include( plugin_dir_path( __FILE__ ) . '/views/admin-competitions.php' );
    5856    }
    5957
     
    6361
    6462        $instance['title'] = strip_tags( $new_instance['title'] );
    65         $instance['seasonId'] = strip_tags( $new_instance['seasonId'] );       
     63        $instance['seasonId'] = strip_tags( $new_instance['seasonId'] );
    6664        $instance['teamsId'] = esc_sql( $new_instance['teamsId'] );       
    6765        return $instance;
     
    7472        echo $before_widget;
    7573
    76         $title = apply_filters( 'wptuts_countdowner_title', $instance['title'] );
    77         $seasonId = apply_filters( 'season_id', $instance['seasonId'] );
    78                
    79         $url = $this->url . "competition-in-season/" . $seasonId;
     74        $title = apply_filters('widget_title', $instance['title']);
     75        $seasonId = $instance['seasonId'];
     76
     77        $url = URL . "competition-in-season/" . $seasonId;
    8078        if( is_array( $instance['teamsId'] ) )
    8179        {
     
    8482
    8583        //echo "".$url."";
    86                
     84
    8785        $json = file_get_contents( $url );
    8886        $data = json_decode( $json, TRUE );
    89        
    90         $table = "<table id='nastrikej'>
     87
     88        $table = "<table class='nastrikej'>
    9189                    <tr>
    9290                        <th>Datum</th>
    9391                        <th>Místo</th>
    94                     </tr>";       
    95                     foreach ( $data["competitions"] as $competition )
     92                    </tr>";
     93        foreach ( $data["competitions"] as $competition )
     94        {
     95            $table.="<tr>";
     96            $table.="<td class='competition'>" . $competition["date"] . "&nbsp;</td><td class='competition-village'><a href='" . $competition["href"] . "'>" . $competition["village"] . "</a></td>";
     97            $table.="</tr>";
     98
     99            if( count( $competition["results"] ) > 0 )
     100            {
     101                foreach( $competition["results"] as $result)
     102                {
     103                    $video = "";
     104                    foreach( $result["youtubes"] as $youtube )
    96105                    {
    97                         $table.="<tr>";
    98                             $table.="<td class='competition'>" . $competition["date"] . "&nbsp;</td><td class='competition-village'><a href='" . $competition["href"] . "'>" . $competition["village"] . "</a></td>";
    99                         $table.="</tr>";
    100                        
    101                         if( count( $competition["results"] ) > 0 )
    102                         {
    103                             foreach( $competition["results"] as $result)
    104                             {
    105                                 $video = "";
    106                                 foreach( $result["youtubes"] as $youtube )
    107                                 {
    108                                     $video.= " <a href='" . $youtube . "' target='_blank' class='competition-video'><img src='http://www.nastrikej.cz/pictures/video-icon.png' alt='video'></a> ";
    109                                 }
    110                                
    111                                 $table.="<tr>";
    112                                     $table.="<td colspan=\"2\" class='competition-result'><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$result["position"]}. {$result["team"]}, čas: {$result["time"]}</small>".$video."</td>";
    113                                     //,{$result["position"]}.místo";
    114                                 $table.="</tr>";                           
    115                             }
    116                         }
    117                        
    118                     }               
     106                        $video.= " <a href='" . $youtube . "' target='_blank' class='competition-video'><img src='http://www.nastrikej.cz/pictures/video-icon.png' alt='video'></a> ";
     107                    }
     108
     109                    $table.="<tr>";
     110                    $table.="<td colspan=\"2\" class='competition-result'><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$result["position"]}. {$result["team"]}, čas: {$result["time"]}</small>".$video."</td>";
     111                    $table.="</tr>";
     112                }
     113            }
     114        }
     115
    119116        $table.= "</table>";
    120                
     117
    121118        include( plugin_dir_path( __FILE__ ) . '/views/widget.php' );
    122119
     
    126123}
    127124
    128 add_action('widgets_init', create_function('', 'return register_widget("nastrikej");'));
     125class NastrikejPositions extends WP_Widget
     126{
     127
     128    public function __construct()
     129    {
     130        parent::__construct( false, $name = __( 'Nastříkej - pořadí' ) );
     131    }
     132
     133    public function form( $instance )
     134    {
     135        $instance = wp_parse_args(
     136            (array) $instance
     137        );
     138
     139        if ( isset( $instance['title'] ) )
     140        {
     141            $title = $instance['title'];
     142        }
     143        else
     144        {
     145            $title = __( 'Pořadí', 'wptuts-countdowner-locale' );
     146        }
     147
     148        if ( isset( $instance['seasonId'] ) )
     149        {
     150            $seasonId = $instance['seasonId'];
     151        }
     152        else
     153        {
     154            $seasonId = "";
     155        }
     156
     157        if ( isset( $instance['teamsId'] ) )
     158        {
     159            $teamsId = $instance['teamsId'];
     160        }
     161        else
     162        {
     163            $teamsId = array();
     164        }
     165
     166        if ( isset( $instance['countTeamsAround'] ) )
     167        {
     168            $countTeamsAround = $instance['countTeamsAround'];
     169        }
     170        else
     171        {
     172            $countTeamsAround = -1;
     173        }
     174
     175        // Display the admin form
     176        include( plugin_dir_path( __FILE__ ) . '/views/admin-positions.php' );
     177    }
     178
     179    public function update( $new_instance, $old_instance )
     180    {
     181        $instance = $old_instance;
     182
     183        $instance['title'] = strip_tags( $new_instance['title'] );
     184        $instance['seasonId'] = strip_tags( $new_instance['seasonId'] );
     185        $instance['teamsId'] = esc_sql( $new_instance['teamsId'] );
     186        $instance['countTeamsAround'] = strip_tags( $new_instance['countTeamsAround'] );
     187        return $instance;
     188    }
     189
     190    public function widget( $args, $instance )
     191    {
     192        extract( $args, EXTR_SKIP );
     193
     194        echo $before_widget;
     195
     196        $title = apply_filters('widget_title', $instance['title']);
     197        $seasonId = $instance['seasonId'];
     198        if(isset($instance['countTeamsAround']))
     199        {
     200            $countTeamsAround = $instance['countTeamsAround'];
     201        }
     202
     203        //positions
     204        $url = URL . "positions-in-season/" . $seasonId;
     205        if( is_array( $instance['teamsId'] ) )
     206        {
     207            $url.= "?team=" . implode( "x", $instance['teamsId'] );
     208        }
     209
     210        if(isset($countTeamsAround))
     211        {
     212            $url .= "&countTeamsAround=" . $countTeamsAround;
     213        }
     214
     215        $json = file_get_contents( $url );
     216        $data = json_decode( $json, TRUE );
     217
     218        //positions
     219        $table = "<table class='nastrikej'>
     220                    <tr>
     221                        <th>Pořadí</th>
     222                        <th>Družstvo</th>
     223                        <th>Body</th>
     224                    </tr>";
     225
     226        foreach( $data["positions"] as $aRowPosition )
     227        {
     228            $strongStartTag = "";
     229            $strongEndTag = "";
     230            if($aRowPosition['strong'] === TRUE)
     231            {
     232                $strongStartTag = "<strong>";
     233                $strongEndTag = "</strong>";
     234            }
     235            $table.= "<tr>
     236                            <td>{$strongStartTag}{$aRowPosition['position']}{$strongEndTag}.</td>
     237                            <td><a href='{$aRowPosition['team_href']}' target='_blank'>{$strongStartTag}{$aRowPosition['team']}{$strongEndTag}</a></td>
     238                            <td>{$strongStartTag}{$aRowPosition['points']}{$strongEndTag}</td>
     239                        </tr>";
     240        }
     241
     242        $table.= "</table>";
     243
     244        include( plugin_dir_path( __FILE__ ) . '/views/widget.php' );
     245
     246        echo $after_widget;
     247    }
     248
     249}
     250
     251
     252add_action('widgets_init', create_function('', 'return register_widget("nastrikejCompetitions");'));
     253add_action('widgets_init', create_function('', 'return register_widget("nastrikejPositions");'));
    129254
    130255?>
Note: See TracChangeset for help on using the changeset viewer.