in a page or entry */ class AlienContact extends Plugin { private $theme= null; /** * Add update beacon support **/ public function action_update_check() { Update::add( 'AlienContact', 'a22354d0-3ba5-11dd-ae16-0800200c9a66', $this->info->version ); } function elements() { return array( 'name' => array( 'id' => 'name', 'type' => 'text', 'label' => 'Name', 'regex' => '/^.{2,}$/', 'required' => TRUE ), 'email' => array( 'id' => 'email', 'type' => 'text', 'label' => 'Email', 'regex' => "/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/", 'required' => TRUE ), 'url' => array( 'id' => 'url', 'type' => 'text', 'label' => 'Website', 'regex' => '/([http]?|[https]?)([:\/\/]?)(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/', 'required' => FALSE ), 'message' => array( 'id' => 'message', 'type' => 'textarea', 'label' => 'Message', 'regex' => '/^[\s\S]{2,}$/', 'required' => TRUE ), 'submit' => array( 'id' => 'submit', 'type' => 'submit', 'label' => 'Send', 'regex' => '', 'required' => FALSE ) ); } public function filter_rewrite_rules( $rules ) { $rules[]= new RewriteRule( array( 'name' => 'aliencontact', 'parse_regex' => '%scripts/aliencontact.js$%i', 'build_str' => 'scripts/aliencontact.js', 'handler' => 'UserThemeHandler', 'action' => 'display_js', 'priority' => 6, 'is_active' => 1, ) ); return $rules; } public function filter_post_content_out( $content ) { $url= Site::get_url( 'host' ) . Controller::get_full_url(); $input= 'post'; $form= self::get_form( $url, $input ); $content= str_replace( '', $form, $content ); return $content; } public function action_handler_display_js( $handler_vars ) { $url= URL::get( 'ajax', array( 'context'=>'submit_form' ) ); include( 'aliencontact.js.php' ); exit; } public function action_ajax_submit_form( $handler ) { echo self::get_form( '', 'post' ); } public function filter_plugin_config( $actions, $plugin_id ) { if ( $plugin_id == $this->plugin_id() ) { $actions[]= _t('Configure'); } return $actions; } public function action_plugin_ui( $plugin_id, $action ) { if ( $plugin_id == $this->plugin_id() ) { switch ( $action ) { case _t('Configure') : $ui= new FormUI( strtolower( get_class( $this ) ) ); $email= $ui->append( 'text', 'email', 'aliencontact__email', _t('Email:') ); $subject= $ui->append( 'text', 'subject', 'aliencontact__subject', _t('Email Subject:') ); $database= $ui->append( 'checkbox', 'database', 'aliencontact__database', _t('Use Database') ); $ui->append( 'submit', 'save', _t('Save') ); $ui->out(); break; } } } public function action_init_theme() { Stack::add( 'template_header_javascript', Site::get_url( 'scripts' ) . '/jquery.js', 'jquery' ); Stack::add( 'template_header_javascript', Site::get_url( 'scripts' ) . '/aliencontact.js', 'aliencontact' ); Stack::add( 'template_stylesheet', array( URL::get_from_filesystem(__FILE__) . '/aliencontact.css', 'screen' ), 'aliencontactcss' ); } /** * Prints the form * */ function form() { $url= Site::get_url( 'host' ) . Controller::get_full_url(); $input= 'post'; echo self::get_form( $url, $input ); } /** * Fetch the form * * @param string $action where the form should be sent to (usually current URL) * @param string $input where input is coming from (only 'post' works now) * @return string the form */ public function get_form( $action = '', $input = 'post' ) { $elements = self::elements(); $output= ''; $values= array(); $errors= array(); if( $input == 'post' ) { foreach( $elements as $key => $field ) { if( isset( $_POST[ 'contactForm_' . $key ] ) || isset( $_POST[$key] ) ) { if( isset( $_POST['contactForm_' . $key] ) ) { $value = $_POST['contactForm_' . $key]; } else { $value = $_POST[$key]; } if( AlienContact::check_input( $value, $key ) != '' ) { $errors[$key]= AlienContact::check_input( $value, $key ); $values[$key]= $value; } else { $values[$key]= $value; } } } } else { foreach( $elements as $key => $field ) { if( isset( $input[ $key ] ) ) { $value = $input[$key]; if( AlienContact::check_input( $value, $key ) != '') { $errors[$key]= AlienContact::check_input($value, $key); $values[$key]= $value; } else { $values[$key]= $value; } } } } if( count( $errors ) != 0 ) { $output .= '
Your message has successfully been delivered.
'; $output .= 'Uh-oh... looks like I made a mistake. What can you expect? I am only a web server after all. Sorry... 1,000 times sorry. Please, give me another chance! I'm begging you! Will you ever talk to me again?'; $output .= '