M_URLGroups

The Membership 2 M URLGroups class.

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/includes/default.rules.php  
  1. class M_URLGroups extends M_Rule { 
  2.  
  3. var $name = 'urlgroups'; 
  4. var $label = 'URL Groups'; 
  5. var $description = "Allows specific URL's to be protected (includes ability to protect using regular expressions)."; 
  6.  
  7. var $rulearea = 'core'; 
  8.  
  9. function get_groups() { 
  10.  
  11. global $wpdb; 
  12.  
  13. $sql = $wpdb->prepare( "SELECT * FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname NOT LIKE (%s) ORDER BY id ASC", '\_%' ); 
  14.  
  15. $results = $wpdb->get_results( $sql ); 
  16.  
  17. if(!empty($results)) { 
  18. return $results; 
  19. } else { 
  20. return false; 
  21.  
  22. function admin_main($data) { 
  23. if(!$data) $data = array(); 
  24. ?> 
  25. <div class='level-operation' id='main-urlgroups'> 
  26. <h2 class='sidebar-name'><?php _e('URL Groups', 'membership');?><span><a href='#remove' id='remove-urlgroups' class='removelink' title='<?php _e("Remove URL Groups from this rules area.", 'membership'); ?>'><?php _e('Remove', 'membership'); ?></a></span></h2> 
  27. <div class='inner-operation'> 
  28. <p><?php _e('Select the URL Groups to be covered by this rule by checking the box next to the relevant URL Group name.', 'membership'); ?></p> 
  29. <?php 
  30. $urlgroups = $this->get_groups(); 
  31.  
  32. if(!empty($urlgroups)) { 
  33. ?> 
  34. <table cellspacing="0" class="widefat fixed"> 
  35. <thead> 
  36. <tr> 
  37. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  38. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('URL Group', 'membership'); ?></th> 
  39. </tr> 
  40. </thead> 
  41.  
  42. <tfoot> 
  43. <tr> 
  44. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  45. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('URL Group', 'membership'); ?></th> 
  46. </tr> 
  47. </tfoot> 
  48.  
  49. <tbody> 
  50. <?php 
  51. foreach($urlgroups as $key => $urlgroup) { 
  52. ?> 
  53. <tr valign="middle" class="alternate" id="urlgroup-<?php echo $urlgroup->id; ?>"> 
  54. <th class="check-column" scope="row"> 
  55. <input type="checkbox" value="<?php echo $urlgroup->id; ?>" name="urlgroups[]" <?php if(in_array($urlgroup->id, $data)) echo 'checked="checked"'; ?>> 
  56. </th> 
  57. <td class="column-name"> 
  58. <strong><?php echo esc_html($urlgroup->groupname); ?></strong> 
  59. </td> 
  60. </tr> 
  61. <?php 
  62. ?> 
  63. </tbody> 
  64. </table> 
  65. <?php 
  66.  
  67. ?> 
  68. </div> 
  69. </div> 
  70. <?php 
  71.  
  72. function on_positive($data) { 
  73.  
  74. $this->data = $data; 
  75.  
  76. add_action( 'pre_get_posts', array(&$this, 'positive_check_request'), 1 ); 
  77.  
  78.  
  79.  
  80. function on_negative($data) { 
  81.  
  82. $this->data = $data; 
  83.  
  84. add_action( 'pre_get_posts', array(&$this, 'negative_check_request'), 1 ); 
  85.  
  86. function positive_check_request($wp) { 
  87.  
  88. global $M_options, $wp_query; 
  89.  
  90. $redirect = false; 
  91. $found = false; 
  92. $host = ''; 
  93. if(is_ssl()) { 
  94. $host = "https://"; 
  95. } else { 
  96. $host = "http://"; 
  97. $host .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  98.  
  99. $exclude = array(); 
  100. if(!empty($M_options['registration_page'])) { 
  101. $exclude[] = get_permalink( (int) $M_options['registration_page'] ); 
  102. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['registration_page'] )); 
  103.  
  104. if(!empty($M_options['account_page'])) { 
  105. $exclude[] = get_permalink( (int) $M_options['account_page'] ); 
  106. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['account_page'] )); 
  107.  
  108. if(!empty($M_options['nocontent_page'])) { 
  109. $exclude[] = get_permalink( (int) $M_options['nocontent_page'] ); 
  110. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['nocontent_page'] )); 
  111.  
  112. if(!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { 
  113. $exclude[] = $host; 
  114. $exclude[] = untrailingslashit($host); 
  115.  
  116. // we have the current page / url - get the groups selected 
  117. foreach((array) $this->data as $group_id) { 
  118. $group = new M_Urlgroup( $group_id ); 
  119.  
  120. if($group->url_matches( $host ) && !in_array(strtolower($host), $exclude)) { 
  121. // We've found a pge in the positive rules so can let the user see it 
  122. $found = true; 
  123.  
  124. if($found !== true) { 
  125. // we need to redirect 
  126. $this->redirect(); 
  127.  
  128.  
  129. function negative_check_request($wp) { 
  130.  
  131. $redirect = false; 
  132. $host = ''; 
  133. if(is_ssl()) { 
  134. $host = "https://"; 
  135. } else { 
  136. $host = "http://"; 
  137. $host .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  138.  
  139. $exclude = array(); 
  140. if(!empty($M_options['registration_page'])) { 
  141. $exclude[] = get_permalink( (int) $M_options['registration_page'] ); 
  142. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['registration_page'] )); 
  143.  
  144. if(!empty($M_options['account_page'])) { 
  145. $exclude[] = get_permalink( (int) $M_options['account_page'] ); 
  146. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['account_page'] )); 
  147.  
  148. if(!empty($M_options['nocontent_page'])) { 
  149. $exclude[] = get_permalink( (int) $M_options['nocontent_page'] ); 
  150. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['nocontent_page'] )); 
  151.  
  152. if(!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { 
  153. $exclude[] = $host; 
  154. $exclude[] = untrailingslashit($host); 
  155.  
  156. // we have the current page / url - get the groups selected 
  157. foreach((array) $this->data as $group_id) { 
  158. $group = new M_Urlgroup( $group_id ); 
  159.  
  160. if($group->url_matches( $host ) && !in_array(strtolower($host), $exclude)) { 
  161. $redirect = true; 
  162.  
  163. if($redirect === true) { 
  164. // we need to redirect 
  165. $this->redirect(); 
  166.  
  167.  
  168. function redirect() { 
  169.  
  170. membership_redirect_to_protected(); 
  171.  
  172.