| @@ -1,27 +1,31 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -abstract class Red_Action { | |
| 4 | - protected $code; | |
| 5 | - protected $type; | |
| 6 | - | |
| 3 | +class Red_Action { | |
| 7 | 4 | function __construct( $values ) { |
| 8 | 5 | if ( is_array( $values ) ) { |
| 9 | 6 | foreach ( $values as $key => $value ) { |
| 10 | - $this->$key = $value; | |
| 7 | + $this->$key = $value; | |
| 11 | 8 | } |
| 12 | 9 | } |
| 13 | 10 | } |
| 14 | 11 | |
| 12 | + function can_change_code() { | |
| 13 | + return false; | |
| 14 | + } | |
| 15 | + | |
| 16 | + function config() { | |
| 17 | + } | |
| 18 | + | |
| 15 | 19 | static function create( $name, $code ) { |
| 16 | 20 | $avail = self::available(); |
| 17 | 21 | |
| 18 | 22 | if ( isset( $avail[ $name ] ) ) { |
| 19 | 23 | if ( ! class_exists( strtolower( $avail[ $name ][1] ) ) ) { |
| 20 | - include_once dirname( __FILE__ ) . '/../actions/' . $avail[ $name ][0]; | |
| 24 | + include dirname( __FILE__ ).'/../actions/'.$avail[ $name ][0]; | |
| 21 | 25 | } |
| 22 | 26 | |
| 23 | - $obj = new $avail[ $name ][1]( array( 'code' => $code ) ); | |
| 27 | + $obj = new $avail[ $name ][1]( array( 'action_code' => $code ) ); | |
| 24 | 28 | $obj->type = $name; |
| 25 | 29 | return $obj; |
| 26 | 30 | } |
| 27 | 31 | |
| @@ -28,31 +32,39 @@ | ||
| 28 | 32 | return false; |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | static function available() { |
| 32 | - return array( | |
| 33 | - 'url' => array( 'url.php', 'Url_Action' ), | |
| 34 | - 'error' => array( 'error.php', 'Error_Action' ), | |
| 36 | + return array( | |
| 37 | + 'url' => array( 'url.php', 'Url_Action' ), | |
| 38 | + 'error' => array( 'error.php', 'Error_Action' ), | |
| 35 | 39 | 'nothing' => array( 'nothing.php', 'Nothing_Action' ), |
| 36 | - 'random' => array( 'random.php', 'Random_Action' ), | |
| 37 | - 'pass' => array( 'pass.php', 'Pass_Action' ), | |
| 40 | + 'random' => array( 'random.php', 'Random_Action' ), | |
| 41 | + 'pass' => array( 'pass.php', 'Pass_Action' ), | |
| 38 | 42 | ); |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | - public function process_before( $code, $target ) { | |
| 42 | - return $target; | |
| 45 | + function type() { | |
| 46 | + return $this->type; | |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | - public function process_after( $code, $target ) { | |
| 49 | + function process_before( $code, $target ) { | |
| 46 | 50 | return true; |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | - public function get_code() { | |
| 50 | - return $this->code; | |
| 53 | + function process_after( $code, $target ) { | |
| 54 | + return true; | |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | - public function get_type() { | |
| 54 | - return $this->type; | |
| 57 | + function can_perform_action () { | |
| 58 | + return true; | |
| 55 | 59 | } |
| 56 | 60 | |
| 57 | - abstract public function needs_target(); | |
| 61 | + function action_codes () { | |
| 62 | + return array(); | |
| 63 | + } | |
| 64 | + | |
| 65 | + function display_actions() { | |
| 66 | + foreach ( $this->action_codes() as $key => $code ) { | |
| 67 | + echo '<option value="'.$key.'"'.( ( $key === intval( $this->action_code ) ) ? ' selected="selected"' : '' ).'>'.sprintf( '%s - %s', $key, $code ).'</option>'; | |
| 68 | + } | |
| 69 | + } | |
| 58 | 70 | } |