HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/diasporameetsafrica.com/wp-content/plugins/wpforms-pdf/src/Storage.php
<?php

namespace WPFormsPDF;

use WPForms\Helpers\File;

/**
 * Storage related helpers class.
 *
 * @since 1.0.0
 */
class Storage {

	/**
	 * PDF storage root directory relative to the WPForms uploads dir.
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	private const PDF_DIR = 'pdf';

	/**
	 * Get the PDFs storage directory.
	 *
	 * @since 1.0.0
	 *
	 * @param int $form_id  Form ID.
	 * @param int $entry_id Entry ID.
	 *
	 * @return string
	 */
	public static function get_dir( int $form_id = 0, int $entry_id = 0 ): string {

		$pdf_dir = File::get_upload_dir() . self::PDF_DIR;

		if ( ! File::mkdir( $pdf_dir ) ) {
			wpforms_pdf()->helpers->log( sprintf( 'Unable to create PDF directory: %s', $pdf_dir ), 'error' );

			return '';
		}

		// Return the root PDF addon storage directory.
		if ( $form_id === 0 || $entry_id === 0 ) {
			return $pdf_dir;
		}

		$entry_dir = sprintf(
			'%1$s/%2$d-%3$s/',
			$pdf_dir,
			$form_id,
			wp_hash( $form_id . '_' . $entry_id )
		);

		if ( ! File::mkdir( $entry_dir ) ) {
			wpforms_pdf()->helpers->log( sprintf( 'Unable to create entry directory: %s', $entry_dir ), 'error' );

			return '';
		}

		return $entry_dir;
	}

	/**
	 * Get the PDFs storage URL.
	 *
	 * @since 1.0.0
	 *
	 * @param int $form_id  Form ID.
	 * @param int $entry_id Entry ID.
	 *
	 * @return string
	 */
	public static function get_url( int $form_id = 0, int $entry_id = 0 ): string {

		$pdf_dir_url = File::get_upload_url() . '/' . self::PDF_DIR;

		// Return the root PDF addon storage directory URL.
		if ( $form_id === 0 || $entry_id === 0 ) {
			return $pdf_dir_url;
		}

		return sprintf(
			'%1$s/%2$d-%3$s/',
			$pdf_dir_url,
			$form_id,
			wp_hash( $form_id . '_' . $entry_id )
		);
	}
}