/wp-content/plugins/nycga-group-files/include/widgets.php

https://github.com/OccupyWallStreet/nycga2 · PHP · 206 lines · 156 code · 44 blank · 6 comment · 20 complexity · 23260eda5f898b11333e2e3d050d9c60 MD5 · raw file

  1. <?php
  2. function nycga_group_files_register_widgets() {
  3. add_action('widgets_init', create_function('', 'return register_widget("NYCGA_Group_Files_Newest_Widget");') );
  4. add_action('widgets_init', create_function('', 'return register_widget("NYCGA_Group_Files_Popular_Widget");') );
  5. }
  6. add_action( 'plugins_loaded', 'nycga_group_files_register_widgets' );
  7. class NYCGA_Group_Files_Newest_Widget extends WP_Widget {
  8. function nycga_group_files_newest_widget() {
  9. $widget_ops = array('description' => __('The most recently uploaded group files','nycga-group-files'));
  10. parent::WP_Widget( false, $name = __( 'Recent Group Files', 'nycga-group-files' ),$widget_ops );
  11. }
  12. function widget( $args, $instance ) {
  13. global $bp;
  14. extract( $args );
  15. $title = apply_filters('widget_title', empty($instance['title'])?__('Recent Group Files','nycga-group-files'):$instance['title']);
  16. echo $before_widget;
  17. echo $before_title .
  18. $title .
  19. $after_title; ?>
  20. <?php
  21. do_action('nycga_group_files_newest_widget_before_html');
  22. /***
  23. * Main HTML Display
  24. */
  25. $document_list = NYCGA_Group_Files::get_list_for_newest_widget( $instance['num_items'], $instance['group_filter'], $instance['featured'] );
  26. if( $document_list && count($document_list) >=1 ) {
  27. echo '<ul class="group-files-recent">';
  28. foreach( $document_list as $item ) {
  29. $document = new NYCGA_Group_Files( $item['id'] );
  30. $group = new NYCGA_Group_Files( $document->group_id );
  31. echo '<li>';
  32. if( $instance['group_filter'] ) {
  33. echo '<a href="' . $document->get_url() . '">' . $document->icon() . ' ' . esc_attr( $document->name ) . '</a>';
  34. } else {
  35. echo sprintf( __('%s posted in %s','nycga-group-files'),'<a href="' . $document->get_url() . '">' . esc_attr( $document->name ) . '</a>','<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>');
  36. }
  37. echo '</li>';
  38. }
  39. echo '</ul>';
  40. } else {
  41. echo '<div class="widget-error">' . __('There are no files to display.', 'nycga-group-files') .'</div></p>';
  42. }
  43. ?>
  44. <?php echo $after_widget; ?>
  45. <?php
  46. }
  47. function update( $new_instance, $old_instance ) {
  48. do_action('nycga_group_files_widget_update');
  49. $instance = $old_instance;
  50. $instance['title'] = strip_tags( $new_instance['title'] );
  51. $instance['group_filter'] = strip_tags( $new_instance['group_filter'] );
  52. $instance['featured'] = strip_tags( $new_instance['featured'] );
  53. $instance['num_items'] = strip_tags( $new_instance['num_items'] );
  54. return $instance;
  55. }
  56. function form( $instance ) {
  57. do_action('nycga_group_files_newest_widget_form');
  58. $instance = wp_parse_args( (array) $instance, array('title'=> '', 'num_items' => 5 ) );
  59. $title = esc_attr( $instance['title'] );
  60. $group_filter = esc_attr( $instance['group_filter'] );
  61. $featured = esc_attr( $instance['featured'] );
  62. $num_items = esc_attr( $instance['num_items'] );
  63. ?>
  64. <p><label><?php _e('Title:','nycga-group-files'); ?></label><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>
  65. <?php if( NYCGA_GROUP_FILES_WIDGET_GROUP_FILTER ) { ?>
  66. <p><label><?php _e('Filter by Group:','nycga-group-files'); ?></label>
  67. <select id="<?php echo $this->get_field_id('group_filter'); ?>" name="<?php echo $this->get_field_name('group_filter'); ?>" >
  68. <option value="0"><?php _e('Select Group...','nycga-group-files'); ?></option>
  69. <?php $groups_list = BP_Groups_Group::get_alphabetically();
  70. foreach( $groups_list['groups'] as $group ) {
  71. echo '<option value="' . $group->id . '" ';
  72. if( $group->id == $group_filter ) echo 'selected="selected"';
  73. echo '>' . stripslashes($group->name) . '</option>';
  74. } ?>
  75. </select></p>
  76. <?php } ?>
  77. <?php if( NYCGA_GROUP_FILES_FEATURED ) { ?>
  78. <p><input type="checkbox" id="<?php echo $this->get_field_id('featured'); ?>" name="<?php echo $this->get_field_name('featured'); ?>" value="1" <?php if( $featured ) echo 'checked="checked"'; ?>>
  79. <label><?php _e('Show featured files only','nycga-group-files'); ?></label></p>
  80. <?php } ?>
  81. <p><label><?php _e( 'Number of items to show:', 'nycga-group-files' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'num_items' ); ?>" name="<?php echo $this->get_field_name( 'num_items' ); ?>" type="text" value="<?php echo esc_attr( $num_items ); ?>" style="width: 30%" /></p>
  82. <?php
  83. }
  84. }
  85. class NYCGA_Group_Files_Popular_Widget extends WP_Widget {
  86. function nycga_group_files_popular_widget() {
  87. $widget_ops = array('description'=> __('The most commonly downloaded group files','nycga-group-files'));
  88. parent::WP_Widget( false, $name = __( 'Popular Group Files', 'nycga-group-files' ),$widget_ops );
  89. }
  90. function widget( $args, $instance ) {
  91. global $bp;
  92. extract( $args );
  93. $title = apply_filters('widget_title', empty($instance['title'])?__('Popular Group Files','nycga-group-files'):$instance['title']);
  94. echo $before_widget;
  95. echo $before_title .
  96. $title .
  97. $after_title; ?>
  98. <?php
  99. do_action('nycga_group_files_popular_widget_before_html');
  100. /***
  101. * Main HTML Display
  102. */
  103. $document_list = NYCGA_Group_Files::get_list_for_popular_widget( $instance['num_items'], $instance['group_filter'], $instance['featured'] );
  104. if( $document_list && count($document_list) >=1 ) {
  105. echo '<ul class="group-files-popular">';
  106. foreach( $document_list as $item ) {
  107. $document = new NYCGA_Group_Files( $item['id'] );
  108. $group = new BP_Groups_Group( $document->group_id );
  109. echo '<li>';
  110. if( $instance['group_filter'] ) {
  111. echo '<a href="' . $document->get_url() . '">' . $document->icon() . ' ' . esc_attr( $document->name ) . '</a>';
  112. } else {
  113. echo sprintf( __('%s posted in %s','nycga-group-files'),'<a href="' . $document->get_url() . '">' . esc_attr( $document->name ) . '</a>','<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>');
  114. }
  115. echo '</li>';
  116. }
  117. echo '</ul>';
  118. } else {
  119. echo '<div class="widget-error">' . __('There are no files to display.', 'nycga-group-files') .'</div></p>';
  120. }
  121. ?>
  122. <?php echo $after_widget; ?>
  123. <?php
  124. }
  125. function update( $new_instance, $old_instance ) {
  126. do_action('nycga_group_files_newest_widget_update');
  127. $instance = $old_instance;
  128. $instance['title'] = strip_tags( $new_instance['title'] );
  129. $instance['group_filter'] = strip_tags( $new_instance['group_filter'] );
  130. $instance['featured'] = strip_tags( $new_instance['featured'] );
  131. $instance['num_items'] = strip_tags( $new_instance['num_items'] );
  132. return $instance;
  133. }
  134. function form( $instance ) {
  135. do_action('nycga_group_files_newest_widget_form');
  136. $instance = wp_parse_args( (array) $instance, array( 'num_items' => 5 ) );
  137. $title = esc_attr( $instance['title'] );
  138. $group_filter = esc_attr( $instance['group_filter'] );
  139. $featured = esc_attr( $instance['featured'] );
  140. $num_items = esc_attr( $instance['num_items'] );
  141. ?>
  142. <p><label><?php _e('Title:','nycga-group-files'); ?></label><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>
  143. <?php if( NYCGA_GROUP_FILES_WIDGET_GROUP_FILTER ) { ?>
  144. <p><label><?php _e('Filter by Group:','nycga-group-files'); ?></label>
  145. <select id="<?php echo $this->get_field_id('group_filter'); ?>" name="<?php echo $this->get_field_name('group_filter'); ?>" >
  146. <option value="0"><?php _e('Select Group...','nycga-group-files'); ?></option>
  147. <?php $groups_list = BP_Groups_Group::get_alphabetically();
  148. foreach( $groups_list['groups'] as $group ) {
  149. echo '<option value="' . $group->id . '" ';
  150. if( $group->id == $group_filter ) echo 'selected="selected"';
  151. echo '>' . stripslashes($group->name) . '</option>';
  152. } ?>
  153. </select></p>
  154. <?php } ?>
  155. <?php if( NYCGA_GROUP_FILES_FEATURED ) { ?>
  156. <p><input type="checkbox" id="<?php echo $this->get_field_id('featured'); ?>" name="<?php echo $this->get_field_name('featured'); ?>" value="1" <?php if( $featured ) echo 'checked="checked"'; ?>>
  157. <label><?php _e('Show featured files only','nycga-group-files'); ?></label></p>
  158. <?php } ?>
  159. <p><label><?php _e( 'Number of items to show:', 'nycga-group-files' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'num_items' ); ?>" name="<?php echo $this->get_field_name( 'num_items' ); ?>" type="text" value="<?php echo esc_attr( $num_items ); ?>" style="width: 30%" /></p>
  160. <?php
  161. }
  162. }