M_Pages

The Membership 2 M Pages class.

Defined (1)

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

/app_old/membershipincludes/includes/default.rules.php  
  1. class M_Pages extends M_Rule { 
  2.  
  3. var $name = 'pages'; 
  4. var $label = 'Pages'; 
  5. var $description = 'Allows specific pages to be protected.'; 
  6.  
  7. var $rulearea = 'public'; 
  8.  
  9. function admin_main($data) { 
  10. if(!$data) $data = array(); 
  11.  
  12. ?> 
  13. <div class='level-operation' id='main-pages'> 
  14. <h2 class='sidebar-name'><?php _e('Pages', 'membership');?><span><a href='#remove' id='remove-pages' class='removelink' title='<?php _e("Remove Pages from this rules area.", 'membership'); ?>'><?php _e('Remove', 'membership'); ?></a></span></h2> 
  15. <div class='inner-operation'> 
  16. <p><?php _e('Select the Pages to be covered by this rule by checking the box next to the relevant pages title.', 'membership'); ?></p> 
  17. <?php 
  18. $args = array( 
  19. 'numberposts' => MEMBERSHIP_PAGE_COUNT,  
  20. 'offset' => 0,  
  21. 'orderby' => 'post_date',  
  22. 'order' => 'DESC',  
  23. 'post_type' => 'page',  
  24. 'post_status' => 'publish' 
  25. ); 
  26.  
  27. $posts = get_posts($args); 
  28.  
  29. // to remove bp specified pages - should be listed on the bp pages group 
  30. $posts = apply_filters( 'staypress_hide_protectable_pages', $posts ); 
  31.  
  32. if($posts) { 
  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('Page title', '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('Page title', 'membership'); ?></th> 
  46. </tr> 
  47. </tfoot> 
  48.  
  49. <tbody> 
  50. <?php 
  51. foreach($posts as $key => $post) { 
  52.  
  53. ?> 
  54. <tr valign="middle" class="alternate" id="post-<?php echo $post->ID; ?>"> 
  55. <th class="check-column" scope="row"> 
  56. <input type="checkbox" value="<?php echo $post->ID; ?>" name="pages[]" <?php if(in_array($post->ID, $data)) echo 'checked="checked"'; ?>> 
  57. </th> 
  58. <td class="column-name"> 
  59. <strong><?php echo esc_html($post->post_title); ?></strong> 
  60. </td> 
  61. </tr> 
  62. <?php 
  63. ?> 
  64. </tbody> 
  65. </table> 
  66. <?php 
  67.  
  68. ?> 
  69. <p class='description'><?php echo sprintf(__("Only the most recent %d pages are shown above.", 'membership'), MEMBERSHIP_PAGE_COUNT); ?></p> 
  70. </div> 
  71. </div> 
  72. <?php 
  73.  
  74. function on_positive($data) { 
  75.  
  76. $this->data = $data; 
  77.  
  78. add_filter('get_pages', array(&$this, 'add_viewable_pages_menu'), 1); 
  79.  
  80. add_filter( 'the_posts', array(&$this, 'check_positive_pages')); 
  81.  
  82.  
  83. function on_negative($data) { 
  84.  
  85. $this->data = $data; 
  86.  
  87. add_filter('get_pages', array(&$this, 'add_unviewable_pages_menu'), 1); 
  88.  
  89. add_filter( 'the_posts', array(&$this, 'check_negative_pages')); 
  90.  
  91.  
  92. function redirect() { 
  93.  
  94. membership_redirect_to_protected(); 
  95.  
  96.  
  97. function get_group() { 
  98.  
  99. global $wpdb; 
  100.  
  101. $sql = $wpdb->prepare( "SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0, 1", '_pages-' . $this->level_id ); 
  102.  
  103. $results = $wpdb->get_var( $sql ); 
  104.  
  105. if(!empty($results)) { 
  106. return $results; 
  107. } else { 
  108. return false; 
  109.  
  110. function add_viewable_pages($wp_query) { 
  111.  
  112. global $M_options; 
  113.  
  114. print_r($wp_query); 
  115.  
  116. if(!$wp_query->is_single && !empty($wp_query->query_vars['post__in'])) { 
  117. // We are not on a single page - so just limit the viewing 
  118. foreach( (array) $this->data as $key => $value ) { 
  119. $wp_query->query_vars['post__in'][] = $value; 
  120.  
  121. $wp_query->query_vars['post__in'] = array_unique($wp_query->query_vars['post__in']); 
  122. } else { 
  123. // We are on a single page - so check for restriction on the_posts 
  124.  
  125.  
  126. function add_viewable_pages_menu($pages) { 
  127.  
  128. $override_pages = apply_filters( 'membership_override_viewable_pages_menu', array() ); 
  129.  
  130. foreach( (array) $pages as $key => $page ) { 
  131. if(!in_array($page->ID, (array) $this->data) && !in_array($page->ID, (array) $override_pages)) { 
  132. unset($pages[$key]); 
  133.  
  134. return $pages; 
  135.  
  136.  
  137. function add_unviewable_pages($wp_query) { 
  138.  
  139. global $M_options; 
  140.  
  141. return; 
  142.  
  143.  
  144. function add_unviewable_pages_menu($pages) { 
  145. foreach( (array) $pages as $key => $page ) { 
  146. if(in_array($page->ID, (array) $this->data)) { 
  147. unset($pages[$key]); 
  148.  
  149. return $pages; 
  150.  
  151. function check_negative_pages( $posts ) { 
  152.  
  153. global $wp_query, $M_options; 
  154.  
  155. if(!$wp_query->is_singular || count($posts) > 1) { 
  156. return $posts; 
  157.  
  158. if(!empty($posts) && count($posts) == 1) { 
  159. // we may be on a restricted post so check the URL and redirect if needed 
  160.  
  161. $redirect = false; 
  162. $url = ''; 
  163.  
  164. $exclude = array(); 
  165. if(!empty($M_options['registration_page'])) { 
  166. $exclude[] = get_permalink( (int) $M_options['registration_page'] ); 
  167. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['registration_page'] )); 
  168.  
  169. if(!empty($M_options['account_page'])) { 
  170. $exclude[] = get_permalink( (int) $M_options['account_page'] ); 
  171. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['account_page'] )); 
  172.  
  173. if(!empty($M_options['nocontent_page'])) { 
  174. $exclude[] = get_permalink( (int) $M_options['nocontent_page'] ); 
  175. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['nocontent_page'] )); 
  176.  
  177. if(!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { 
  178. $exclude[] = $host; 
  179. $exclude[] = untrailingslashit($host); 
  180.  
  181. foreach($posts as $post) { 
  182. if($post->post_type != 'page') { 
  183. continue; 
  184.  
  185. if(!in_array(strtolower( get_permalink($post->ID) ), $exclude)) { 
  186. $url = get_permalink($post->ID); 
  187.  
  188. // Check if we have a url available to check 
  189. if(empty($url)) { 
  190. return $posts; 
  191.  
  192. // we have the current page / url - get the groups selected 
  193. $group_id = $this->get_group(); 
  194.  
  195. if($group_id) { 
  196. $group = new M_Urlgroup( $group_id ); 
  197.  
  198. if( $group->url_matches( $url ) ) { 
  199. $redirect = true; 
  200.  
  201. if($redirect === true && !empty($M_options['nocontent_page'])) { 
  202. // we need to redirect 
  203. $this->redirect(); 
  204. } else { 
  205. return $posts; 
  206.  
  207.  
  208. return $posts; 
  209.  
  210.  
  211. function check_positive_pages( $posts ) { 
  212.  
  213. global $wp_query, $M_options; 
  214.  
  215. if(!$wp_query->is_singular || count($posts) > 1) { 
  216. return $posts; 
  217.  
  218. if(!empty($posts) && count($posts) == 1) { 
  219. // we may be on a restricted post so check the URL and redirect if needed 
  220.  
  221. $redirect = false; 
  222. $found = false; 
  223. $url = ''; 
  224.  
  225. $exclude = array(); 
  226. if(!empty($M_options['registration_page'])) { 
  227. $exclude[] = get_permalink( (int) $M_options['registration_page'] ); 
  228. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['registration_page'] )); 
  229.  
  230. if(!empty($M_options['account_page'])) { 
  231. $exclude[] = get_permalink( (int) $M_options['account_page'] ); 
  232. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['account_page'] )); 
  233.  
  234. if(!empty($M_options['nocontent_page'])) { 
  235. $exclude[] = get_permalink( (int) $M_options['nocontent_page'] ); 
  236. $exclude[] = untrailingslashit(get_permalink( (int) $M_options['nocontent_page'] )); 
  237.  
  238. if(!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { 
  239. $exclude[] = $host; 
  240. $exclude[] = untrailingslashit($host); 
  241.  
  242. foreach($posts as $post) { 
  243. if($post->post_type != 'page') { 
  244. continue; 
  245.  
  246. if(!in_array(strtolower( get_permalink($post->ID) ), $exclude)) { 
  247. $url = get_permalink($post->ID); 
  248.  
  249. // Check if we have a url available to check 
  250. if(empty($url)) { 
  251. return $posts; 
  252.  
  253. // we have the current page / url - get the groups selected 
  254. $group_id = $this->get_group(); 
  255.  
  256. if($group_id) { 
  257. $group = new M_Urlgroup( $group_id ); 
  258.  
  259. if( $group->url_matches( $url ) ) { 
  260. $found = true; 
  261.  
  262. if($found !== true && !empty($M_options['nocontent_page'])) { 
  263. // we need to redirect 
  264. $this->redirect(); 
  265. } else { 
  266. return $posts; 
  267.  
  268.  
  269. return $posts; 
  270.  
  271.  
  272.