d99e70bf5fa88b49f1c05e6c327ed652354a8fd7
[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         
26         $Query = $this->load($options);
27         
28         // Get the next post, if available      
29         if ( ! $Query->have_posts() ) return;
30         // Queue the post data
31         $Query->the_post();
32
33         if ( ! empty($args) )
34             extract($args, EXTR_SKIP);
35         
36                 $title = $before_title . ( ! empty($options['title']) ? $options['title'] : get_the_title() ) . $after_title;
37                 $summary = ! empty($options['summary']) ? $options['summary'] : get_the_excerpt();
38                 $link = ! empty($options['link']) ? $options['link'] : __('Read more');
39         
40         $image = '';
41         if ( $post_thumbnail_id = get_post_thumbnail_id() ) {
42             $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
43             // $image = " style=\"background-image: url('" . $post_thumbnail_url . "')\"";
44             $image = " data-url=\"" . $post_thumbnail_url . "\"";
45         }
46         
47         $featured = ( 'on' == $options['featured'] );
48         
49         $classes = array('tile');
50         if ( $featured ) {
51             $classes[] = 'featured-tile';
52             $classes[] = 'two-thirds-tile';
53         } else {
54             $classes[] = 'third-tile';
55         }
56         
57         if ( isset($options['vignette']) && 'dark' == $options['vignette'] )
58             $classes[] = 'tag-dark';
59         
60         ?>
61             <div <?php echo post_class(join(' ', $classes)); ?>>
62                 <a class="tile-link" href="<?php the_permalink(); ?>"><?php echo $title; ?></a>
63                 <div class="background-image">
64                     <div class="featured-image"<?php echo $image; ?>></div>
65                     <?php if ( $featured ): ?><div class="background-vignette"></div><?php endif; ?>
66                 </div>
67                 <div class="tile-content">
68                     <h1><?php echo $title; ?></h1>
69                     <div class="summary"><?php echo $summary; ?></div>
70                     <p><a href="<?php the_permalink(); ?>"><?php echo $link; ?>&nbsp;&rsaquo;</a></p>
71                 </div>        
72             </div>
73         <?php
74     }
75
76     public function form( array $options ) {
77         if ( empty( $options['link'] ) ) $options['link'] = __('Read more');
78                 ?>
79                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?></label>
80                 <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>
81
82                 <p><label for="<?php echo $this->get_field_id('summary'); ?>"><?php _e('Summary'); ?></label>
83                 <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>
84
85                 <p><label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Call to Action'); ?></label>
86                 <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>
87         
88                 <p><label for="<?php echo $this->get_field_id('featured'); ?>">
89             <input type="hidden" name="<?php echo $this->get_field_name('featured'); ?>" value="off">
90             <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' : ''; ?>>
91             <?php _e('Featured'); ?></label>
92                 </p>
93         
94                 <?php
95     }
96
97 } // END class WebKitPostTileWidget
98
99 register_widget('WebKitPostTileWidget');