wid-subscribe.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. add_action( 'widgets_init', 'd_subscribes' );
  3. function d_subscribes() {
  4. register_widget( 'd_subscribe' );
  5. }
  6. class d_subscribe extends WP_Widget {
  7. function d_subscribe() {
  8. $widget_ops = array( 'classname' => 'd_subscribe', 'description' => '显示邮箱订阅组件' );
  9. $this->WP_Widget( 'd_subscribe', 'Yusi-邮箱订阅', $widget_ops, $control_ops );
  10. }
  11. function widget( $args, $instance ) {
  12. extract( $args );
  13. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '邮件订阅';
  14. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  15. $nid = empty( $instance['nid'] ) ? '' : $instance['nid'];
  16. $info = empty( $instance['info'] ) ? '订阅精彩内容' : $instance['info'];
  17. $placeholder = empty( $instance['placeholder'] ) ? 'your@email.com' : $instance['placeholder'];
  18. $output .= $before_widget;
  19. if ( $title )
  20. $output .= $before_title . $title . $after_title;
  21. $output .= '<form action="http://list.qq.com/cgi-bin/qf_compose_send" target="_blank" method="post">'
  22. . '<p>' . $info . '</p>'
  23. . '<input type="hidden" name="t" value="qf_booked_feedback" /><input type="hidden" name="id" value="' . $nid . '" />'
  24. . '<input type="email" name="to" class="rsstxt" placeholder="' . $placeholder . '" value="" required /><input type="submit" class="rssbutton" value="订阅" />'
  25. . '</form>';
  26. $output .= $after_widget;
  27. echo $output;
  28. }
  29. function update( $new_instance, $old_instance ) {
  30. $instance = $old_instance;
  31. $instance['title'] = strip_tags($new_instance['title']);
  32. $instance['nid'] = strip_tags( $new_instance['nid'] );
  33. $instance['info'] = strip_tags( $new_instance['info'] );
  34. $instance['placeholder'] = strip_tags( $new_instance['placeholder'] );
  35. return $instance;
  36. }
  37. function form($instance) {
  38. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  39. $nid = esc_attr( $instance['nid'] );
  40. $info = esc_attr( $instance['info'] );
  41. $placeholder = esc_attr( $instance['placeholder'] );
  42. ?>
  43. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  44. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
  45. <p><label for="<?php echo $this->get_field_id( 'nid' ); ?>">nId:</label>
  46. <input class="widefat" id="<?php echo $this->get_field_id( 'nid' ); ?>" name="<?php echo $this->get_field_name( 'nid' ); ?>" type="text" value="<?php echo $nid; ?>" /></p>
  47. <p><label for="<?php echo $this->get_field_id( 'info' ); ?>">提示文字:</label>
  48. <input class="widefat" id="<?php echo $this->get_field_id( 'info' ); ?>" name="<?php echo $this->get_field_name( 'info' ); ?>" type="text" value="<?php echo $info; ?>" /></p>
  49. <p><label for="<?php echo $this->get_field_id( 'placeholder' ); ?>">占位文字:</label>
  50. <input class="widefat" id="<?php echo $this->get_field_id( 'placeholder' ); ?>" name="<?php echo $this->get_field_name( 'placeholder' ); ?>" type="text" value="<?php echo $placeholder; ?>" /></p>
  51. <p class="description">本工具基于 <a href="http://list.qq.com/" target="_blank">QQ邮件列表</a> 服务。</p>
  52. <?php
  53. }
  54. }
  55. ?>