M_Urlgroup

The Membership 2 M Urlgroup class.

Defined (1)

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

/app_old/membershipincludes/classes/class.urlgroup.php  
  1. class M_Urlgroup { 
  2.  
  3. var $build = 1; 
  4.  
  5. var $db; 
  6. var $tables = array('membership_levels', 'membership_rules', 'subscriptions', 'subscriptions_levels', 'membership_relationships', 'membermeta', 'communications', 'urlgroups'); 
  7.  
  8. var $membership_levels; 
  9. var $membership_rules; 
  10. var $membership_relationships; 
  11. var $subscriptions; 
  12. var $subscriptions_levels; 
  13. var $membermeta; 
  14. var $communications; 
  15. var $urlgroups; 
  16.  
  17. // if the data needs reloaded, or hasn't been loaded yet 
  18. var $dirty = true; 
  19.  
  20. var $group; 
  21.  
  22. function __construct( $id = false) { 
  23.  
  24. global $wpdb; 
  25.  
  26. $this->db =& $wpdb; 
  27.  
  28. foreach($this->tables as $table) { 
  29. $this->$table = membership_db_prefix($this->db, $table); 
  30.  
  31. $this->id = $id; 
  32.  
  33.  
  34. function M_Urlgroup( $id = false ) { 
  35. $this->__construct( $id ); 
  36.  
  37. function get_group() { 
  38. $sql = $this->db->prepare( "SELECT * FROM {$this->urlgroups} WHERE id = %d ", $this->id ); 
  39.  
  40. return $this->db->get_row( $sql ); 
  41.  
  42. function editform() { 
  43.  
  44. $this->group = $this->get_group(); 
  45.  
  46. echo '<table class="form-table">'; 
  47.  
  48. echo '<tr class="form-field form-required">'; 
  49. echo '<th style="" scope="row" valign="top">' . __('Group name', 'membership') . '</th>'; 
  50. echo '<td valign="top"><input name="groupname" type="text" size="50" title="' . __('Group name', 'membership') . '" style="width: 50%;" value="' . esc_attr(stripslashes($this->group->groupname)) . '" /></td>'; 
  51. echo '</tr>'; 
  52.  
  53. echo '<tr class="form-field form-required">'; 
  54. echo '<th style="" scope="row" valign="top">' . __('Page URLs', 'membership') . '</th>'; 
  55. echo '<td valign="top"><textarea name="groupurls" rows="15" cols="40">' . esc_html(stripslashes($this->group->groupurls)) . '</textarea>'; 
  56. // Display some instructions for the message. 
  57. echo "<br/><em style='font-size:smaller;'>" . __("You should place each page URL or expression on a new line.", 'membership') . "</em>"; 
  58. echo '</td>'; 
  59. echo '</tr>'; 
  60.  
  61. echo '<tr class="form-field form-required">'; 
  62. echo '<th style="" scope="row" valign="top">' . __('Strip query strings from URL', 'membership') . '</th>'; 
  63. echo '<td valign="top" align="left">'; 
  64. echo '<select name="stripquerystring">'; 
  65. echo '<option value="0"'; 
  66. if($this->group->stripquerystring == 0) echo ' selected="selected"'; 
  67. echo '>' . __('No', 'membership') . '</option>'; 
  68. echo '<option value="1"'; 
  69. if($this->group->stripquerystring == 1) echo ' selected="selected"'; 
  70. echo '>' . __('Yes', 'membership') . '</option>'; 
  71. echo '</select>'; 
  72. echo "<br/><em style='font-size:smaller;'>" . __("Remove any query string values prior to checking URL.", 'membership') . "</em>"; 
  73. echo '</td></tr>'; 
  74.  
  75. echo '<tr class="form-field form-required">'; 
  76. echo '<th style="" scope="row" valign="top">' . __('Regular Expression', 'membership') . '</th>'; 
  77. echo '<td valign="top" align="left">'; 
  78. echo '<select name="isregexp">'; 
  79. echo '<option value="0"'; 
  80. if($this->group->isregexp == 0) echo ' selected="selected"'; 
  81. echo '>' . __('No', 'membership') . '</option>'; 
  82. echo '<option value="1"'; 
  83. if($this->group->isregexp == 1) echo ' selected="selected"'; 
  84. echo '>' . __('Yes', 'membership') . '</option>'; 
  85. echo '</select>'; 
  86. echo "<br/><em style='font-size:smaller;'>" . __("If any of the page URLs are regular expressions then set this to yes.", 'membership') . "</em>"; 
  87. echo '</td></tr>'; 
  88.  
  89. echo '</table>'; 
  90.  
  91.  
  92. function addform() { 
  93.  
  94. echo '<table class="form-table">'; 
  95.  
  96. echo '<tr class="form-field form-required">'; 
  97. echo '<th style="" scope="row" valign="top">' . __('Group name', 'membership') . '</th>'; 
  98. echo '<td valign="top"><input name="groupname" type="text" size="50" title="' . __('Group name', 'membership') . '" style="width: 50%;" value="" /></td>'; 
  99. echo '</tr>'; 
  100.  
  101. echo '<tr class="form-field form-required">'; 
  102. echo '<th style="" scope="row" valign="top">' . __('Page URLs', 'membership') . '</th>'; 
  103. echo '<td valign="top"><textarea name="groupurls" rows="15" cols="40"></textarea>'; 
  104. // Display some instructions for the message. 
  105. echo "<br/><em style='font-size:smaller;'>" . __("You should place each page URL or expression on a new line.", 'membership') . "</em>"; 
  106. echo '</td>'; 
  107. echo '</tr>'; 
  108.  
  109. echo '<tr class="form-field form-required">'; 
  110. echo '<th style="" scope="row" valign="top">' . __('Strip query strings from URL', 'membership') . '</th>'; 
  111. echo '<td valign="top" align="left">'; 
  112. echo '<select name="stripquerystring">'; 
  113. echo '<option value="0"'; 
  114. echo '>' . __('No', 'membership') . '</option>'; 
  115. echo '<option value="1"'; 
  116. echo '>' . __('Yes', 'membership') . '</option>'; 
  117. echo '</select>'; 
  118. echo "<br/><em style='font-size:smaller;'>" . __("Remove any query string values prior to checking URL.", 'membership') . "</em>"; 
  119. echo '</td></tr>'; 
  120.  
  121. echo '<tr class="form-field form-required">'; 
  122. echo '<th style="" scope="row" valign="top">' . __('Regular Expression', 'membership') . '</th>'; 
  123. echo '<td valign="top" align="left">'; 
  124. echo '<select name="isregexp">'; 
  125. echo '<option value="0"'; 
  126. echo '>' . __('No', 'membership') . '</option>'; 
  127. echo '<option value="1"'; 
  128. echo '>' . __('Yes', 'membership') . '</option>'; 
  129. echo '</select>'; 
  130. echo "<br/><em style='font-size:smaller;'>" . __("If any of the page URLs are regular expressions then set this to yes.", 'membership') . "</em>"; 
  131. echo '</td></tr>'; 
  132.  
  133. echo '</table>'; 
  134.  
  135.  
  136. function add() { 
  137.  
  138. $insert = array( 
  139. "groupname" => $_POST['groupname'],  
  140. "groupurls" => $_POST['groupurls'],  
  141. "isregexp" => $_POST['isregexp'],  
  142. "stripquerystring" => $_POST['stripquerystring'] 
  143. ); 
  144.  
  145. return $this->db->insert( $this->urlgroups, $insert ); 
  146.  
  147.  
  148. function update() { 
  149.  
  150. $updates = array( 
  151. "groupname" => $_POST['groupname'],  
  152. "groupurls" => $_POST['groupurls'],  
  153. "isregexp" => $_POST['isregexp'],  
  154. "stripquerystring" => $_POST['stripquerystring'] 
  155. ); 
  156.  
  157. return $this->db->update( $this->urlgroups, $updates, array( "id" => $this->id) ); 
  158.  
  159.  
  160. function delete() { 
  161.  
  162. $sql = $this->db->prepare( "DELETE FROM {$this->urlgroups} WHERE id = %d", $this->id ); 
  163.  
  164. return $this->db->query( $sql ); 
  165.  
  166.  
  167. // processing 
  168. function url_matches( $host, $exclude = array() ) { 
  169.  
  170. $this->group = $this->get_group(); 
  171.  
  172. $groups = array_map('strtolower', array_map('trim', explode("\n", $this->group->groupurls))); 
  173.  
  174. if($this->group->stripquerystring == 1 && strpos($host, '?') !== false) { 
  175. $host = substr( $host, 0, strpos($host, '?')); 
  176.  
  177. if($this->group->isregexp == 0) { 
  178. // straight match 
  179. $newgroups = array_map('untrailingslashit', $groups); 
  180. $groups = array_merge($groups, $newgroups); 
  181. if(in_array( strtolower($host), $groups ) ) { 
  182. return true; 
  183. } else { 
  184. return false; 
  185. } else { 
  186. //reg expression match 
  187. $matchstring = ""; 
  188. foreach($groups as $key => $value) { 
  189. if($matchstring != "") $matchstring .= "|"; 
  190.  
  191. if( stripos($value, '\/') ) { 
  192. $matchstring .= stripcslashes($value); 
  193. } else { 
  194. $matchstring .= $value; 
  195.  
  196. // switched to using a character that won't be in a url as the start and end markers 
  197. $matchstring = "#" . $matchstring . "#i"; 
  198.  
  199. if(preg_match($matchstring, $host, $matches) ) { 
  200. return true; 
  201. } else { 
  202. return false; 
  203.  
  204.