/**
	 * Returns the table lines for the requested Attachment ID'S (ajax call)
	 * 
	 * @param array $file_ids
	 * @param string $email_subject
	 * @param int $product_id			needed to create unique name, if more products are displayed (e.g. product page)
	 * @param bool $new_attachments
	 * @return string			HTML Code to insert in table on settings page
	 */
	public function &get_attachment_files_info( array $file_ids, $email_subject, $product_id = 0, $new_attachments = false )
	{
		$html = '';
		
		if( empty( $file_ids ) )
			return $html;
		
		$selected_files = $this->wc_email_att->get_attachment_files_info ( $file_ids );
		
		$id = $this->inputfields_param[ $email_subject ]['att_name'];
		$wpml_lang = isset( $this->options[ $this->inputfields_param[ $email_subject ]['att_wpml_id'] ] ) ? $this->options[ $this->inputfields_param[ $email_subject ]['att_wpml_id'] ] : array();
		$lang = $new_attachments ? array() :  $wpml_lang;

		if( $product_id != 0 )
		{
			$id = str_replace( '[]', '[' . $product_id . '][]', $id );
			if( ! $new_attachments )
			{		//	load existing language settings
				$pm = get_post_meta( $product_id );
				$lang = isset( $pm[ $this->inputfields_param[ $email_subject ]['att_wpml_id'] ]) ? $this->inputfields_param[ $email_subject ]['att_wpml_id'] : array();
			}
		}
		
		$columns = array(
				'thumb' => __( 'Thumb', WC_Email_Att::TEXT_DOMAIN ),
				'name' => __( 'Name', WC_Email_Att::TEXT_DOMAIN ),
			);
		$columns = apply_filters( 'wc_eatt_wpml_column', $columns );
		
		$columns['id'] = __( 'ID', WC_Email_Att::TEXT_DOMAIN );
		$columns['path'] = __( 'Location', WC_Email_Att::TEXT_DOMAIN );
		$columns['button_remove'] = '';
		
		$element = array(
				'type'				=> WC_Addons_Email_Att::FILE_MEDIA,
				'button_remove'		=> __( 'Remove', WC_Email_Att::TEXT_DOMAIN ),
				'button_remove_tip' => __( 'Removes this file from the list of attachments for this email, but does not delete the file. You can reuse it later at any time.', WC_Email_Att::TEXT_DOMAIN ),
				'info'				=> __( 'Selected files:', WC_Email_Att::TEXT_DOMAIN ),
				'columns'			=> $columns,
				'js_prefix'			=> ($product_id == 0) ? self::PREFIX_JS_NAMES : self::PREFIX_JS_NAMES_PROD,
				'id'				=> $id,
				'std'				=> $selected_files,
				'attachment_infos'	=> $this->wc_email_att->attachment_infos,
				'language_name'		=> $this->inputfields_param[ $email_subject ]['att_wpml_name'],
				'language'			=> $lang,
				'subject'			=> $email_subject,
				'rows_only'			=> true,
				'wc_settings_page'	=> true,
				'product_id'		=> $product_id
			);
		
			ob_start();
			do_action( 'woocommerce_admin_field_' . WC_Addons_Email_Att::FILE_MEDIA, $element );
			$buffer = ob_get_contents();
			ob_clean();
			
			return $buffer;
	}
Exemplo n.º 2
0
	/**
	 * 
	 * @param string $file
	 * @param string $filename
	 * @return int
	 */
	protected function add_attachment($file, $filename)
	{
		$dest_file = trailingslashit(WC_Email_Att_Func::get_full_upload_path($this->options_new['upload_folder'])).$filename;
		
		if(file_exists($dest_file))
		{
			$unique = uniqid('_');
			$path_parts = pathinfo($filename);
			$filename = $path_parts['filename'].$unique.'.'.$path_parts['extension'];
			$dest_file = trailingslashit(WC_Email_Att_Func::get_full_upload_path($this->options_new['upload_folder'])).$filename;
		}
		
		if(!copy($file, $dest_file))
		{
			return 0;
		}
		
		$parent_post_id = WC_Email_Att::instance()->email_post->ID;

		// Check the type of tile. We'll use this as the 'post_mime_type'.
		$filetype = wp_check_filetype( basename( $dest_file ), null );
		
		// Get the path to the upload directory.
		$wp_upload_dir = wp_upload_dir();
		
		// Prepare an array of post data for the attachment.
		$attachment = array(
				'guid'           => $wp_upload_dir['baseurl'].trailingslashit($this->options_new['upload_folder']).$filename, 
				'post_mime_type' => $filetype['type'],
				'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $dest_file ) ),
				'post_content'   => '',
				'post_status'    => 'inherit'
			);
		
		// Insert the attachment.
		$attach_id = wp_insert_attachment( $attachment, $dest_file, $parent_post_id );

		// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
		require_once( ABSPATH . 'wp-admin/includes/image.php' );

		// Generate the metadata for the attachment, and update the database record.
		$attach_data = wp_generate_attachment_metadata( $attach_id, $dest_file );
		wp_update_attachment_metadata( $attach_id, $attach_data );
		
		return $attach_id;
	}
Exemplo n.º 3
0
	/**
	 * Deletes all the files attached to the only EMail attachment post
	 */
	protected function delete_all_attachment_files()
	{
		$args = array( 
			'post_type' => 'attachment', 
			'posts_per_page' => -1, 
			'post_status' =>'any', 
			'post_parent' => WC_Email_Att::instance()->email_post->ID ); 
		
		$attachments = get_posts( $args );
		
		$to_delete = count( $attachments );
		$deleted = 0;
		foreach ( $attachments as $key => $attachment ) 
		{
			if( false !== wp_delete_attachment( $attachment->ID, true ) )
			{
				$deleted++;
			}
		}

		if( $to_delete == $deleted )
		{
			$notice_option = array(
				'message' => sprintf( __( 'All %d attachment file(s) could be permanently deleted.', WC_Email_Att::TEXT_DOMAIN ), $to_delete ), 
				'error' => false
				);
		}
		else
		{
			$diff = $to_delete - $deleted;
			$notice_option = array(
				'message' => sprintf( __( '%d attachment file(s) could not be deleted, %d file(s) could be deleted.', WC_Email_Att::TEXT_DOMAIN ), $diff, $deleted ), 
				'error' => true
				);
		}
			
		update_option( WC_Email_Att::OPTIONNAME_NOTICE, $notice_option );
	}
<?php
if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly

global $wc_email_att_skip_files, $wc_email_att_htaccess, $wc_email_att_plugin_base_name, $wc_email_att_are_activation_hooks;

$wc_email_att_plugin_path = str_replace( basename( __FILE__ ), '', __FILE__ );

/**
 * load woocommerce_email_attachments main class, which loads needed classes with autoload when needed
 **/
require_once $wc_email_att_plugin_path . 'classes/class-wc-email-att.php';

	// create object
WC_Email_Att::instance();

WC_Email_Att::$show_activation = true;			//	true to show deactivation and uninstall checkbox
WC_Email_Att::$show_uninstall = true;
WC_Email_Att::$plugin_path = $wc_email_att_plugin_path;
WC_Email_Att::$plugin_url = trailingslashit( plugins_url( '', plugin_basename( __FILE__ ) ) );		//	also set in init hook to allow other plugins to change it in a filter hook
WC_Email_Att::$plugin_base_name = $wc_email_att_plugin_base_name;
WC_Email_Att::$skip_files = $wc_email_att_skip_files;

WC_Email_Att_Func::$htaccess = $wc_email_att_htaccess;

WC_Email_Att::instance()->init();
	

	//	allow plugins to load, which depend on this plugin being already loaded
do_action( 'wc_email_att_plugin_loaded' );

Exemplo n.º 5
0
	/**
	 * Set plugin url with filters hooked by other plugins
	 */
	public function handler_wp_init()
	{
		self::$plugin_url = trailingslashit(plugins_url( '', plugin_basename( dirname( __FILE__ ) ) ) );
		
			//	init WPML and reload options to fill default values of WPML
		$this->wpml->init();
		$this->options = self::get_options_default( $this->emailsubjects );
	}
   /**
	 * Checks for OPT_DEL_ON_UNINSTALL -> removes option and all files and the last folder, if empty
	 */
   public function on_uninstall()
   {
		$this->delete_message_options(WC_Email_Att::OPTIONNAME_NOTICE);
		$this->delete_message_options(WC_Email_Att::OPTIONNAME_UPDATE);
		
		$this->options = get_option( WC_Email_Att::OPTIONNAME, array() );
		
		//	already deleted on deactivation
		if( empty( $this->options ) )
		{
			WC_Email_Att::instance()->delete_the_only_post();
			
					//	fallback - delete option from old version also, but leave the files
			delete_option( 'woocommerce_email_attachments' );
			return;
		}
		
		//	fallback - default behaviour if not exist - Delete in any case to clean up database
		if( ! isset($this->options['del_on_uninstall'] ) || $this->options['del_on_uninstall'] )
		{
			delete_option( WC_Email_Att::OPTIONNAME );
			WC_Email_Att::instance()->delete_the_only_post();
			
					//	fallback - delete option from old version also, but leave the files
			delete_option( 'woocommerce_email_attachments' );
		}
   }