Ejemplo n.º 1
0
	/**
	 * 
	 */
	public function __construct() 
	{
		if(!isset(self::$admin_message))
		{
			self::$admin_message = '';
		}
		
		if(!isset(self::$plugin_url))
		{
			self::$plugin_url = '';
		}
		if(!isset(self::$skip_files))
		{
			self::$skip_files = array();
		}
		
		if(!isset(self::$chars_to_remove))
		{
			self::$chars_to_remove = array('§');
		}
		
		if(!isset(self::$chars_to_be_replaced))
		{
			self::$chars_to_be_replaced = array('ä', 'ö', 'ü');
		}
		
		if(!isset(self::$chars_to_be_replaced_by))
		{
			self::$chars_to_be_replaced_by = array('ae', 'oe', 'ue');
		}
		
		self::init_inputfield_values();
		
		$this->attachments_sent = false;
		$this->options = get_option(self::OPTIONNAME, array());

		
		// fallback to standard options settings
		if(empty ($this->options))
		{
			$this->options = woocommerce_email_attachments_activation::init_default_options();
		}
		else if(version_compare($this->options[self::OPT_VERSION], self::VERSION, '!='))
		{
			$this->options = woocommerce_email_attachments_activation::update_options_version($this->options);
			update_option(woocommerce_email_attachments::OPTIONNAME, $this->options);
		}

					//	load scripts only on our option page
		if(false !== strpos($_SERVER['REQUEST_URI'], 'tab=inoplugs_email'))
		{
			inoplugs_plupload::activate();
			
					//	attach to plupload filters for output
			add_filter('inoplugs_plupload_translate_messages', array(&$this, 'handler_translate_messages'), 10, 2);
			add_filter('inoplugs_plupload_set_hidden_field_data', array(&$this, 'handler_set_hidden_field_data'), 10, 2);

			add_action('admin_init', array(&$this, 'handler_wp_admin_init'));
			add_action('admin_print_styles', array(&$this, 'handler_wp_admin_print_styles'));
		}
	
		
		
		$this->current_tab = ( isset($_GET['tab'] ) ) ? $_GET['tab'] : 'general';

		//	Add all tabs required
		$this->settings_tabs = array(
			woocommerce_email_attachments::TABID => __( 'E-Mail Attachments', 'woocommerce_email_attachments' )
		);

		// Load in the new settings tabs and attach handler.
		add_action( 'woocommerce_settings_tabs', array( &$this, 'add_tab' ), 10 );

		// Run these actions when generating the settings tabs.
		foreach ( $this->settings_tabs as $name => $label ) {
			add_action( 'woocommerce_settings_tabs_' . $name, array( &$this, 'set_tabs' ), 10 );
			add_action( 'woocommerce_update_options_' . $name, array( &$this, 'save_settings' ), 10 );
		}
		
		// Add the settings fields to each tab.
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_UPLOAD, array( &$this, 'set_upload_file_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_CHECKBOX, array( &$this, 'set_checkbox_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_AJAXLOAD, array( &$this, 'set_ajaxload_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_TOGGLESTART, array( &$this, 'set_toggle_start_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_TOGGLETITLE, array( &$this, 'set_toggle_title_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_TOGGLEAREA, array( &$this, 'set_toggle_area_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_TOGGLEEND, array( &$this, 'set_toggle_end_field' ), 10 );
		add_action( 'woocommerce_admin_field_'.woocommerce_email_attachments::FORM_EMAIL, array( &$this, 'set_email_field' ), 10 );
		
		//	add fields to tab on admin page
		add_action( 'woocommerce_email_attachment_settings', array( &$this, 'add_settings_fields' ), 10 );
		
		// add attachment notification text to email content
		add_action( 'woocommerce_email_footer', array( &$this, 'handler_email_attachment_footer' ), 10 );

		//	Arrach to subject hooks to know, which type of mail is generated to attach a notification message in footer section
		add_filter('woocommerce_email_subject_new_order', array(&$this, 'handler_subject_new_order'), 10, 2);
		add_filter('woocommerce_email_subject_customer_processing_order', array(&$this, 'handler_subject_customer_processing_order'), 10, 2);
		add_filter('woocommerce_email_subject_customer_completed_order', array(&$this, 'handler_subject_customer_completed_order'), 10, 2);
		add_filter('woocommerce_email_subject_customer_invoice', array(&$this, 'handler_subject_customer_invoice'), 10, 2);
		add_filter('woocommerce_email_subject_customer_note', array(&$this, 'handler_subject_customer_note'), 10, 2);
		add_filter('woocommerce_email_subject_low_stock', array(&$this, 'handler_subject_low_stock'), 10, 2);
		add_filter('woocommerce_email_subject_no_stock', array(&$this, 'handler_subject_no_stock'), 10, 2);
		add_filter('woocommerce_email_subject_backorder', array(&$this, 'handler_subject_backorder'), 10, 2);
		add_filter('woocommerce_email_subject_customer_new_account', array(&$this, 'handler_subject_customer_new_account'), 10, 2);
		
		//	Arrach to E-Mail Handlers for CC, BCC, additional headers
		add_filter('woocommerce_email_headers', array(&$this, 'handler_email_headers'), 10, 2);
		
		//	Arrach to E-Mail Handlers for attachments
		add_filter('woocommerce_email_attachments', array(&$this, 'handler_email_attachments'), 20, 2);	
		
		//	Attach to WP filename filters
		add_filter('sanitize_file_name_chars', array(&$this, 'handler_wp_sanitize_file_name_chars'), 10, 2);
		add_filter('sanitize_file_name', array(&$this, 'handler_wp_sanitize_file_name'), 10, 2);
			
			//	Ajax Callbacks for file upload and delete
		if(false !== strpos($_SERVER['REQUEST_URI'], 'admin-ajax.php'))
		{
			inoplugs_plupload::activate();
			
			add_action( 'wp_ajax_nopriv_delete-file', array(&$this,'handler_ajax_delete_file') );
			add_action( 'wp_ajax_delete-file', array(&$this,'handler_ajax_delete_file') );
			
			//	inoplugs_plupload callback
			add_action(self::VAL_PLUPLOAD_CALLBACK, array(&$this,'handler_ajax_wc_upload_file'), 10, 1);
			
		}
	}