Changeset 980878
- Timestamp:
- 09/05/2014 01:19:12 AM (11 years ago)
- Location:
- wp-ticket-framework/trunk
- Files:
-
- 1 added
- 2 edited
-
. (modified) (1 prop)
-
readme.txt (added)
-
ticket-framework.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-ticket-framework/trunk
-
Property
svn:ignore
set to
README.md
.git
.gitignore
.gitmodules
deploy/
-
Property
svn:ignore
set to
-
wp-ticket-framework/trunk/ticket-framework.php
r350473 r980878 9 9 */ 10 10 11 /** 12 * WordPress Ticket Framework 13 * @package wpTix 14 */ 11 15 class wpTix { 12 16 … … 14 18 var $query_var = 'do'; 15 19 16 function wpTix(){17 $this->__construct();18 }19 20 /** 21 * Standard constructor 22 * @internal 23 */ 20 24 function __construct(){ 21 25 global $wpdb; … … 27 31 add_action( 'parse_query', array( &$this, 'parse_query' ), 1 ); 28 32 add_action( 'did_ticket', array( &$this, 'did_ticket' ), 11 ); 29 // add_action( 'template_redirect', array( &$this, 'template_redirect' ), 11 );30 33 31 34 register_activation_hook( __FILE__, array( &$this, '_activate' )); 32 35 } 33 36 37 /** 38 * Init action handler. Sets up rewrites for tickets 39 * @internal 40 */ 34 41 function init(){ 35 42 // add the rewrite rules … … 38 45 } 39 46 47 /** 48 * Parse_query action handler. Closes the requested ticket. 49 * @internal 50 */ 40 51 function parse_query( $query ){ 41 52 if( !empty( $query->query_vars[ $this->query_var ] )) … … 43 54 } 44 55 56 /** 57 * Configures whether or not to delete the ticket & redirect to siteurl when the ticket is closed 58 * @param boolean $yes whether or not to call self::did_ticket on ticket close 59 */ 45 60 function clean_up_after( $yes = TRUE ){ 46 61 if( $yes ) … … 50 65 } 51 66 52 function template_redirect(){ 53 if( $template = get_page_template() ) 54 include( $template ); 55 die; 56 } 57 67 /** 68 * Get the URL for a given ticket 69 * @param string $ticket_name 70 * @return string URL 71 */ 58 72 function get_url( $ticket_name ){ 59 73 global $wp_rewrite; 60 74 61 75 if ( empty( $wp_rewrite->permalink_structure )) 62 return get_ settings( 'siteurl' ) .'/?'. $this->query_var .'='. urlencode( $ticket_name );76 return get_option( 'siteurl' ) .'/?'. $this->query_var .'='. urlencode( $ticket_name ); 63 77 else 64 return get_settings( 'siteurl' ) .'/'. $this->url_base .'/'. urlencode( $ticket_name ); 65 } 66 67 68 78 return get_option( 'siteurl' ) .'/'. $this->url_base .'/'. urlencode( $ticket_name ); 79 } 80 81 82 /** 83 * Test if a ticket exists with a given name 84 * @param string $ticket_name Unique ticket name 85 * @return wpTix|false Ticket or false if not found 86 */ 69 87 function is_ticket( $ticket_name ){ 70 88 global $wpdb; … … 90 108 } 91 109 110 /** 111 * Create a ticket 112 * @param string $action Hook to invoke when the ticket is closed 113 * @param string $ticket_name Unique ticket name 114 * @param mixed $arg Argument(s) to pass to $action 115 * @return wpTix|false The ticket that was created, or false on error. 116 */ 92 117 function register_ticket( $action, $ticket_name, $arg = '' ){ 93 118 global $wpdb; … … 144 169 }//end update_ticket 145 170 171 /** 172 * Close a ticket and perform its corresponding action 173 * @param string $ticket_name Unique ticket name 174 */ 146 175 function do_ticket( $ticket_name ){ 147 176 global $wpdb; … … 151 180 $ticket = $this->is_ticket( $ticket_name ); 152 181 if( ! $ticket ) 153 die( wp_redirect( get_ settings( 'siteurl' ), '301'));182 die( wp_redirect( get_option( 'siteurl' ), '301')); 154 183 155 184 // do the specified action … … 160 189 } 161 190 191 /** 192 * Close (delete) a ticket and redirect to siteurl 193 * @internal 194 */ 162 195 function did_ticket( $ticket ){ 163 196 $this->delete_ticket( $ticket->ticket ); 164 die( wp_redirect( get_settings( 'siteurl' ), '301')); 165 } 166 197 die( wp_redirect( get_option( 'siteurl' ), '301')); 198 } 199 200 /** 201 * Delete a ticket 202 * @param string $ticket_name Unique ticket name 203 * @return boolean sucessful deletion 204 */ 167 205 function delete_ticket( $ticket_name ){ 168 206 global $wpdb; … … 179 217 180 218 181 219 /** 220 * Generate a 32-character random, unique ticket name 221 * @return string ticket name 222 */ 182 223 function generate_md5() { 183 224 while( TRUE ){ … … 188 229 } 189 230 231 /** 232 * Generate a random, unique ticket name with a given length, using a given alphabet 233 * @param int $len string length 234 * @param string $alphabet valid characters 235 * @return string random string 236 */ 190 237 function generate_string( $len = 5, $alphabet = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ){ 191 238 while( TRUE ){ … … 196 243 } 197 244 245 /** 246 * Generate a random string of a given length, using a given alphabet 247 * @static 248 * @param int $len string length 249 * @param string $alphabet valid characters 250 * @return string random string 251 */ 198 252 function _generate_string( $len = 5, $alphabet = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ){ 199 253 $key = ''; … … 204 258 } 205 259 206 207 208 260 /** 261 * @internal 262 */ 209 263 function _is_action( $action ) { 210 264 global $wpdb; … … 222 276 return $action_id; 223 277 } 224 278 279 /** 280 * @internal 281 */ 225 282 function _insert_action( $action ) { 226 283 global $wpdb; … … 236 293 } 237 294 $action_id = (int) $wpdb->insert_id; 238 295 239 296 wp_cache_add( $action, $action_id, 'ticket_actions' ); 240 297 } … … 244 301 245 302 246 303 /** 304 * Activation hook. Sets up database tables. 305 * @internal 306 */ 247 307 function _activate() { 248 308 global $wpdb; … … 282 342 } 283 343 284 $wptix = new wpTix(); 344 function wptix() 345 { 346 global $wptix; 347 348 if ( ! $wptix ) 349 { 350 $wptix = new wpTix; 351 }//end if 352 353 return $wptix; 354 }//end wptix 355 356 // Single instance of wpTix 357 wptix();
Note: See TracChangeset
for help on using the changeset viewer.