M_Downloads

The Membership 2 M Downloads class.

Defined (1)

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

/app_old/membershipincludes/includes/default.rules.php  
  1. class M_Downloads extends M_Rule { 
  2.  
  3. var $name = 'downloads'; 
  4. var $label = 'Downloads'; 
  5. var $description = 'Allows media uploaded to the WordPress media library to be protected.'; 
  6.  
  7. var $rulearea = 'public'; 
  8.  
  9. function admin_main($data) { 
  10.  
  11. global $wpdb, $M_options; 
  12.  
  13. if(!$data) $data = array(); 
  14.  
  15. ?> 
  16. <div class='level-operation' id='main-downloads'> 
  17. <h2 class='sidebar-name'><?php _e('Downloads', 'membership');?><span><a href='#remove' id='remove-downloads' class='removelink' title='<?php _e("Remove Downloads from this rules area.", 'membership'); ?>'><?php _e('Remove', 'membership'); ?></a></span></h2> 
  18. <div class='inner-operation'> 
  19. <p><?php _e('Select the Downloads / Media to be covered by this rule by checking the box next to the relevant group name.', 'membership'); ?></p> 
  20. <?php 
  21. $mediasql = $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s", '_membership_protected_content' ); 
  22. $mediaids = $wpdb->get_col( $mediasql ); 
  23.  
  24. if(!empty($mediaids)) { 
  25. // We have some ids so grab the information 
  26. $attachmentsql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status != %s AND ID IN(" . implode(", ", $mediaids) . ")", 'attachment', 'trash' ); 
  27.  
  28. $attachments = $wpdb->get_results( $attachmentsql ); 
  29. ?> 
  30. <table cellspacing="0" class="widefat fixed"> 
  31. <thead> 
  32. <tr> 
  33. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  34. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('Download / Group name', 'membership'); ?></th> 
  35. </tr> 
  36. </thead> 
  37. <tfoot> 
  38. <tr> 
  39. <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th> 
  40. <th style="" class="manage-column column-name" id="name" scope="col"><?php _e('Download / Group name', 'membership'); ?></th> 
  41. </tr> 
  42. </tfoot> 
  43.  
  44. <tbody> 
  45. <?php 
  46. if(!empty($M_options['membershipdownloadgroups'])) { 
  47.  
  48. foreach($M_options['membershipdownloadgroups'] as $key => $value) { 
  49. if(!empty($value)) { 
  50. ?> 
  51. <tr valign="middle" class="alternate" id="group-<?php echo esc_attr(stripslashes(trim($value))); ?>"> 
  52. <th class="check-column" scope="row"> 
  53. <input type="checkbox" value="<?php echo esc_attr(stripslashes(trim($value))); ?>" name="downloads[]" <?php if(in_array(esc_attr(stripslashes(trim($value))), $data)) echo 'checked="checked"'; ?>> 
  54. </th> 
  55. <td class="column-name"> 
  56. <strong><?php echo esc_html(stripslashes(trim($value))); ?></strong> 
  57. </td> 
  58. </tr> 
  59. <?php 
  60.  
  61. } else { 
  62. ?> 
  63. <tr valign="middle" class="alternate" id="group-nogroup"> 
  64. <td class="column-name" colspan='2'> 
  65. <?php echo __('You have no download groups set, please visit the membership options page to set them up.', 'membership'); ?> 
  66. </td> 
  67. </tr> 
  68. <?php 
  69.  
  70. ?> 
  71. </tbody> 
  72. </table> 
  73.  
  74. </div> 
  75. </div> 
  76. <?php 
  77.  
  78. function can_view_download($area, $group) { 
  79.  
  80. switch($area) { 
  81.  
  82. case 'positive': if(in_array($group, (array) $this->data)) { 
  83. return true; 
  84. break; 
  85.  
  86. case 'negative': if(in_array($group, (array) $this->data)) { 
  87. return false; 
  88. break; 
  89.  
  90. default: return false; 
  91.  
  92.  
  93.