/app_old/membershipincludes/addons/member.widget.php

  1. <?php 
  2. /** 
  3. Addon Name: Membership Widget 
  4. Description: Membership widgets 
  5. Author: Barry (Incsub) 
  6. Author URI: http://caffeinatedb.com 
  7. */ 
  8.  
  9. class membershipleveltext extends WP_Widget { 
  10.  
  11. function membershipleveltext() { 
  12.  
  13. $locale = apply_filters( 'membership_locale', get_locale() ); 
  14. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" ); 
  15.  
  16. if ( file_exists( $mofile ) ) 
  17. load_textdomain( 'membership', $mofile ); 
  18.  
  19. $widget_ops = array( 'classname' => 'membershipleveltext', 'description' => __('Membership Level Text', 'membership') ); 
  20. $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'membershipleveltext'); 
  21. $this->WP_Widget( 'membershipleveltext', __('Membership Level Text', 'membership'), $widget_ops, $control_ops ); 
  22.  
  23. function widget( $args, $instance ) { 
  24.  
  25. extract( $args ); 
  26.  
  27. // build the check array 
  28. $defaults = array( 
  29. 'title' => '',  
  30. 'content' => '',  
  31. 'level' => 'none' 
  32. ); 
  33.  
  34. foreach($defaults as $key => $value) { 
  35. if(isset($instance[$key])) { 
  36. $defaults[$key] = $instance[$key]; 
  37.  
  38. extract($defaults); 
  39.  
  40. $show = false; 
  41.  
  42. switch($level) { 
  43.  
  44. case 'none': if(!is_user_logged_in() || !current_user_is_member()) { 
  45. $show = true; 
  46. break; 
  47.  
  48. default: if(current_user_on_level($level)) { 
  49. $show = true; 
  50. break; 
  51.  
  52.  
  53. if($show) { 
  54. echo $before_widget; 
  55. $title = apply_filters('widget_title', $title ); 
  56.  
  57. if ( !empty($title) ) { 
  58. echo $before_title . $title . $after_title; 
  59.  
  60. echo do_shortcode($content); 
  61.  
  62. echo $after_widget; 
  63.  
  64.  
  65. function update( $new_instance, $old_instance ) { 
  66. $instance = $old_instance; 
  67.  
  68. $defaults = array( 
  69. 'title' => '',  
  70. 'content' => '',  
  71. 'level' => 'none' 
  72. ); 
  73.  
  74. foreach ( $defaults as $key => $val ) { 
  75. $instance[$key] = $new_instance[$key]; 
  76.  
  77. if ( !current_user_can('unfiltered_html') ) { 
  78. $instance['content'] = stripslashes( wp_filter_post_kses( addslashes($instance['content']) ) ); // wp_filter_post_kses() expects slashed 
  79.  
  80. return $instance; 
  81.  
  82. function get_membership_levels() { 
  83.  
  84. global $wpdb; 
  85.  
  86. $sql = $wpdb->prepare( "SELECT * FROM " . membership_db_prefix($wpdb, 'membership_levels') . " WHERE level_active = %d", 1 ); 
  87.  
  88. return $wpdb->get_results($sql); 
  89.  
  90.  
  91. function form( $instance ) { 
  92.  
  93. $defaults = array( 
  94. 'title' => '',  
  95. 'content' => '',  
  96. 'level' => 'none' 
  97. ); 
  98. $instance = wp_parse_args( (array) $instance, $defaults ); 
  99.  
  100. extract($instance); 
  101.  
  102. ?> 
  103. <p> 
  104. <?php _e('Show the content below if the user is on the following level:', 'membership'); ?> 
  105. </p> 
  106. <p> 
  107. <select name='<?php echo $this->get_field_name( 'level' ); ?>' id='<?php echo $this->get_field_id( 'level' ); ?>'> 
  108. <option value='none' <?php selected($level, 'none'); ?>><?php _e('Non-member or not logged in', 'membership'); ?></option> 
  109. <?php 
  110. $levels = $this->get_membership_levels(); 
  111.  
  112. foreach($levels as $alevel) { 
  113. ?> 
  114. <option value='<?php echo $alevel->id; ?>' <?php selected($level, $alevel->id); ?>><?php echo $alevel->level_title; ?></option> 
  115. <?php 
  116. ?> 
  117. </select> 
  118. </p> 
  119. <p> 
  120. <?php _e('Title', 'membership'); ?><br/> 
  121. <input type='text' class='widefat' name='<?php echo $this->get_field_name( 'title' ); ?>' id='<?php echo $this->get_field_id( 'title' ); ?>' value='<?php echo esc_attr(stripslashes($instance['title'])); ?>' /> 
  122. </p> 
  123. <p> 
  124. <?php _e('Content', 'membership'); ?><br/> 
  125. <textarea class='widefat' name='<?php echo $this->get_field_name( 'content' ); ?>' id='<?php echo $this->get_field_id( 'content' ); ?>' rows='5' cols='40'><?php echo stripslashes($instance['content']); ?></textarea> 
  126. </p> 
  127. <?php 
  128.  
  129. class membershipsubtext extends WP_Widget { 
  130.  
  131. function membershipsubtext() { 
  132.  
  133. $locale = apply_filters( 'membership_locale', get_locale() ); 
  134. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" ); 
  135.  
  136. if ( file_exists( $mofile ) ) 
  137. load_textdomain( 'membership', $mofile ); 
  138.  
  139. $widget_ops = array( 'classname' => 'membershipsubtext', 'description' => __('Membership Subscription Text', 'membership') ); 
  140. $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'membershipsubtext'); 
  141. $this->WP_Widget( 'membershipsubtext', __('Membership Subscription Text', 'membership'), $widget_ops, $control_ops ); 
  142.  
  143. function widget( $args, $instance ) { 
  144.  
  145. extract( $args ); 
  146.  
  147. // build the check array 
  148. $defaults = array( 
  149. 'title' => '',  
  150. 'content' => '',  
  151. 'sub' => 'none' 
  152. ); 
  153.  
  154. foreach($defaults as $key => $value) { 
  155. if(isset($instance[$key])) { 
  156. $defaults[$key] = $instance[$key]; 
  157.  
  158. extract($defaults); 
  159.  
  160. $show = false; 
  161.  
  162. switch($sub) { 
  163.  
  164. case 'none': if(!is_user_logged_in() || !current_user_is_member()) { 
  165. $show = true; 
  166. break; 
  167.  
  168. default: if(current_user_on_subscription($sub)) { 
  169. $show = true; 
  170. break; 
  171.  
  172.  
  173. if($show) { 
  174. echo $before_widget; 
  175. $title = apply_filters('widget_title', $title ); 
  176.  
  177. if ( !empty($title) ) { 
  178. echo $before_title . $title . $after_title; 
  179.  
  180. echo do_shortcode($content); 
  181.  
  182. echo $after_widget; 
  183.  
  184.  
  185. function update( $new_instance, $old_instance ) { 
  186. $instance = $old_instance; 
  187.  
  188. $defaults = array( 
  189. 'title' => '',  
  190. 'content' => '',  
  191. 'sub' => 'none' 
  192. ); 
  193.  
  194. foreach ( $defaults as $key => $val ) { 
  195. $instance[$key] = $new_instance[$key]; 
  196.  
  197. if ( !current_user_can('unfiltered_html') ) { 
  198. $instance['content'] = stripslashes( wp_filter_post_kses( addslashes($instance['content']) ) ); // wp_filter_post_kses() expects slashed 
  199.  
  200. return $instance; 
  201.  
  202. function get_subscriptions() { 
  203.  
  204. global $wpdb; 
  205.  
  206. $sql = $wpdb->prepare( "SELECT * FROM " . membership_db_prefix($wpdb, 'subscriptions') . " WHERE sub_active = %d", 1 ); 
  207.  
  208. return $wpdb->get_results($sql); 
  209.  
  210.  
  211. function form( $instance ) { 
  212.  
  213. $defaults = array( 
  214. 'title' => '',  
  215. 'content' => '',  
  216. 'sub' => 'none' 
  217. ); 
  218. $instance = wp_parse_args( (array) $instance, $defaults ); 
  219.  
  220. extract($instance); 
  221.  
  222. ?> 
  223. <p> 
  224. <?php _e('Show the content below if the user is on the following subscription:', 'membership'); ?> 
  225. </p> 
  226. <p> 
  227. <select name='<?php echo $this->get_field_name( 'sub' ); ?>' id='<?php echo $this->get_field_id( 'sub' ); ?>'> 
  228. <option value='none' <?php selected($sub, 'none'); ?>><?php _e('Non-member or not logged in', 'membership'); ?></option> 
  229. <?php 
  230. $subs = $this->get_subscriptions(); 
  231.  
  232. foreach($subs as $asub) { 
  233. ?> 
  234. <option value='<?php echo $asub->id; ?>' <?php selected($sub, $asub->id); ?>><?php echo $asub->sub_name; ?></option> 
  235. <?php 
  236. ?> 
  237. </select> 
  238. </p> 
  239. <p> 
  240. <?php _e('Title', 'membership'); ?><br/> 
  241. <input type='text' class='widefat' name='<?php echo $this->get_field_name( 'title' ); ?>' id='<?php echo $this->get_field_id( 'title' ); ?>' value='<?php echo esc_attr(stripslashes($instance['title'])); ?>' /> 
  242. </p> 
  243. <p> 
  244. <?php _e('Content', 'membership'); ?><br/> 
  245. <textarea class='widefat' name='<?php echo $this->get_field_name( 'content' ); ?>' id='<?php echo $this->get_field_id( 'content' ); ?>' rows='5' cols='40'><?php echo stripslashes($instance['content']); ?></textarea> 
  246. </p> 
  247. <?php 
  248.  
  249. function membershipwidget_register() { 
  250. register_widget( 'membershipleveltext' ); 
  251. register_widget( 'membershipsubtext' ); 
  252.  
  253. add_action( 'widgets_init', 'membershipwidget_register' ); 
  254.  
  255.  
  256. ?> 
.