<?php

class Intense_Login_Form extends Intense_Shortcode {

    function __construct() {
        parent::__construct();

        global $intense_visions_options;

        $this->title = __( 'Login Form', 'intense' );
        $this->description = __( 'Adds a WordPress login form to the post/page', 'intense' );
        $this->category = __( 'Elements', 'intense' );
        $this->show_preview = false;        
        $this->is_container = false;
    }

    function shortcode( $atts, $content = null ) {
        extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

        $output = '';

        if ( !is_user_logged_in() ) {
            if ( is_numeric( $redirect ) ) {
                $redirect = get_permalink( $redirect );
            }

            if ( $redirect ) {
                $redirect_url = $redirect;
            } else {
                $redirect_url = get_permalink();
            }

            $atts = array(                
                'echo' => false,
                'redirect' => $redirect_url,
                'form_id' => $id,
                'label_username' => $label_username,
                'label_password' => $label_password,
                'label_remember' => $label_remember,
                'label_log_in' => $label_log_in,
                'remember'       => $remember,                
                'value_remember' => $value_remember
            );

            if ( empty( $id ) ) unset( $atts['form_id'] );
            if ( empty( $label_username ) ) unset( $atts['label_username'] );
            if ( empty( $label_password ) ) unset( $atts['label_password'] );
            if ( empty( $label_remember ) ) unset( $atts['label_remember'] );
            if ( empty( $label_log_in ) ) unset( $atts['label_log_in'] );
            if ( empty( $remember ) ) unset( $atts['remember'] );
            if ( empty( $value_remember ) ) unset( $atts['value_remember'] );

            ob_start();
            wp_login_form();
            $output = ob_get_clean();   

            if ( $show_lost_password ) {
                $output .= '<br><a href="' . wp_lostpassword_url( get_permalink() ) . '" class="intense lost-password" title="' . __( 'Lost your password?' ) . '">' . __( 'Lost your password?' ) . '</a>';
            }
        } else {
            $output = do_shortcode( $content );
        }

        return $output;
    }

}
