Reduce Safari Technology Preview Release Notes posts shown on homepage
[WebKit-https.git] / Websites / webkit.org / wp-content / themes / webkit / widgets / post.php
1 <?php
2 /**
3  * WebKitPostTileWidget class
4  * A WordPress widget to show a post tile on the home page
5  **/
6
7 defined('WPINC') || header('HTTP/1.1 403') & exit; // Prevent direct access
8
9 if ( ! class_exists('WP_Widget') ) return;
10         
11 class WebKitPostTileWidget extends WP_Widget {
12
13     public function __construct() {
14         parent::WP_Widget(false, 
15                         __('Post Tile'), 
16                         array('description' => __('Post tile for the home page'))
17                 );
18     }
19     
20     public function load( array $options = array() ) {
21         return Front_Page_Posts::WP_Query();
22     }
23
24     public function widget( array $args, array $options ) {
25         $Query = $this->load($options);
26         
27         // Get the next post, if available      
28         if ( ! $Query->have_posts() ) return;
29
30         // Queue the post data
31         $Query->the_post();
32
33         $featured = ( 'on' == $options['featured'] );
34         if ( ! $featured ) {
35             // Prevent Safari Technology Preview release note posts from showing up when not a featured post.
36             while ( in_category('safari-technology-preview') && $Query->have_posts() ) {
37                 $Query->the_post();
38                 continue;
39             }
40         }
41
42         if ( ! empty($args) )
43             extract($args, EXTR_SKIP);
44         
45                 $title = $before_title . ( ! empty($options['title']) ? $options['title'] : get_the_title() ) . $after_title;
46                 $summary = ! empty($options['summary']) ? $options['summary'] : get_the_excerpt();
47                 $link = ! empty($options['link']) ? $options['link'] : __('Read more');
48         
49         $image = '';
50         if ( $post_thumbnail_id = get_post_thumbnail_id() ) {
51             $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
52             $image = " data-url=\"" . $post_thumbnail_url . "\"";
53         }
54         
55         $classes = array('tile');
56         if ( $featured ) {
57             $classes[] = 'featured-tile';
58             $classes[] = 'two-thirds-tile';
59         } else {
60             $classes[] = 'third-tile';
61         }
62         
63         if ( isset($options['vignette']) && 'dark' == $options['vignette'] )
64             $classes[] = 'tag-dark';
65         
66         ?>
67             <div <?php echo post_class(join(' ', $classes)); ?>>
68                 <a class="tile-link" href="<?php the_permalink(); ?>"><?php echo $title; ?></a>
69                 <div class="background-image">
70                     <div class="featured-image"<?php echo $image; ?>></div>
71                     <?php if ( $featured ): ?><div class="background-vignette"></div><?php endif; ?>
72                 </div>
73                 <div class="tile-content">
74                     <h1><?php echo $title; ?></h1>
75                     <div class="summary"><?php echo $summary; ?></div>
76                     <p><a href="<?php the_permalink(); ?>"><?php echo $link; ?>&nbsp;&rsaquo;</a></p>
77                 </div>        
78             </div>
79         <?php
80     }
81
82     public function form( array $options ) {
83         if ( empty( $options['link'] ) ) $options['link'] = __('Read more');
84                 ?>
85                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?></label>
86                 <input type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" class="widefat" value="<?php echo $options['title']; ?>" placeholder="Current Post Title"></p>
87
88                 <p><label for="<?php echo $this->get_field_id('summary'); ?>"><?php _e('Summary'); ?></label>
89                 <input type="text" name="<?php echo $this->get_field_name('summary'); ?>" id="<?php echo $this->get_field_id('summary'); ?>" class="widefat" value="<?php echo $options['summary']; ?>" placeholder="Current Post Excerpt"></p>
90
91                 <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Call to Action'); ?></label>
92                 <input type="text" name="<?php echo $this->get_field_name('link'); ?>" id="<?php echo $this->get_field_id('link'); ?>" class="widefat" value="<?php echo $options['link']; ?>"></p>
93         
94                 <p><label for="<?php echo $this->get_field_id('featured'); ?>">
95             <input type="hidden" name="<?php echo $this->get_field_name('featured'); ?>" value="off">
96             <input type="checkbox" name="<?php echo $this->get_field_name('featured'); ?>" id="<?php echo $this->get_field_id('featured'); ?>" class="widefat" value="on" <?php echo ( 'on' == $options['featured'] ) ? 'checked' : ''; ?>>
97             <?php _e('Featured'); ?></label>
98                 </p>
99                 <?php
100     }
101
102 } // END class WebKitPostTileWidget
103
104 register_widget('WebKitPostTileWidget');