Plugin Directory

Changeset 980878


Ignore:
Timestamp:
09/05/2014 01:19:12 AM (11 years ago)
Author:
misterbisson
Message:

tested for wp4

Includes sweet code cleanup by https://github.com/borkweb and inline docs by https://github.com/daveross .

Location:
wp-ticket-framework/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-ticket-framework/trunk

    • Property svn:ignore set to
      README.md
      .git
      .gitignore
      .gitmodules
      deploy/
  • wp-ticket-framework/trunk/ticket-framework.php

    r350473 r980878  
    99*/
    1010
     11/**
     12 * WordPress Ticket Framework
     13 * @package wpTix
     14 */
    1115class wpTix {
    1216
     
    1418    var $query_var = 'do';
    1519
    16     function wpTix(){
    17         $this->__construct();
    18     }
    19 
     20    /**
     21     * Standard constructor
     22     * @internal
     23     */
    2024    function __construct(){
    2125        global $wpdb;
     
    2731        add_action( 'parse_query', array( &$this, 'parse_query' ), 1 );
    2832        add_action( 'did_ticket', array( &$this, 'did_ticket' ), 11 );
    29 //      add_action( 'template_redirect', array( &$this, 'template_redirect' ), 11 );
    3033
    3134        register_activation_hook( __FILE__, array( &$this, '_activate' ));
    3235    }
    3336
     37    /**
     38     * Init action handler. Sets up rewrites for tickets
     39     * @internal
     40     */
    3441    function init(){
    3542        // add the rewrite rules
     
    3845    }
    3946
     47    /**
     48     * Parse_query action handler. Closes the requested ticket.
     49     * @internal
     50     */
    4051    function parse_query( $query ){
    4152        if( !empty( $query->query_vars[ $this->query_var ] ))
     
    4354    }
    4455
     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     */
    4560    function clean_up_after( $yes = TRUE ){
    4661        if( $yes )
     
    5065    }
    5166
    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     */
    5872    function get_url( $ticket_name ){
    5973        global $wp_rewrite;
    6074
    6175        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 );
    6377        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     */
    6987    function is_ticket( $ticket_name ){
    7088        global $wpdb;
     
    90108    }
    91109
     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     */
    92117    function register_ticket( $action, $ticket_name, $arg = '' ){
    93118        global $wpdb;
     
    144169    }//end update_ticket
    145170
     171    /**
     172     * Close a ticket and perform its corresponding action
     173     * @param string $ticket_name Unique ticket name
     174     */
    146175    function do_ticket( $ticket_name ){
    147176        global $wpdb;
     
    151180        $ticket = $this->is_ticket( $ticket_name );
    152181        if( ! $ticket )
    153             die( wp_redirect( get_settings( 'siteurl' ), '301'));
     182            die( wp_redirect( get_option( 'siteurl' ), '301'));
    154183
    155184        // do the specified action
     
    160189    }
    161190
     191    /**
     192     * Close (delete) a ticket and redirect to siteurl
     193     * @internal
     194     */
    162195    function did_ticket( $ticket ){
    163196        $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     */
    167205    function delete_ticket( $ticket_name ){
    168206        global $wpdb;
     
    179217
    180218
    181 
     219    /**
     220     * Generate a 32-character random, unique ticket name
     221     * @return string ticket name
     222     */
    182223    function generate_md5() {
    183224        while( TRUE ){
     
    188229    }
    189230
     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     */
    190237    function generate_string( $len = 5, $alphabet = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ){
    191238        while( TRUE ){
     
    196243    }
    197244
     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     */
    198252    function _generate_string( $len = 5, $alphabet = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ){
    199253        $key = '';
     
    204258    }
    205259
    206 
    207 
    208 
     260    /**
     261     * @internal
     262     */
    209263    function _is_action( $action ) {
    210264        global $wpdb;
     
    222276        return $action_id;
    223277    }
    224    
     278
     279    /**
     280     * @internal
     281     */
    225282    function _insert_action( $action ) {
    226283        global $wpdb;
     
    236293            }
    237294            $action_id = (int) $wpdb->insert_id;
    238            
     295
    239296            wp_cache_add( $action, $action_id, 'ticket_actions' );
    240297        }
     
    244301
    245302
    246 
     303    /**
     304     * Activation hook. Sets up database tables.
     305     * @internal
     306     */
    247307    function _activate() {
    248308        global $wpdb;
     
    282342}
    283343
    284 $wptix = new wpTix();
     344function 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
     357wptix();
Note: See TracChangeset for help on using the changeset viewer.