> */ public static function all() { $french = 0 === strpos( determine_locale(), 'fr' ); $dir = VEFDK_PLUGIN_DIR . 'assets/samples/'; $list = array( 'extract' => array( 'label' => __( 'Company registration extract', 'vefdocskit' ), 'text' => __( 'Protected against editing, printing and copying.', 'vefdocskit' ), 'pages' => 1, 'name' => $french ? 'extrait-societe-protege.pdf' : 'company-extract-protected.pdf', 'path' => $dir . ( $french ? 'extrait-societe-protege.pdf' : 'company-extract-protected.pdf' ), ), 'contract' => array( 'label' => __( 'Service contract', 'vefdocskit' ), 'text' => __( 'Encrypted with AES-256, no password to open it.', 'vefdocskit' ), 'pages' => 4, 'name' => $french ? 'contrat-prestation-aes256.pdf' : 'service-contract-aes256.pdf', 'path' => $dir . ( $french ? 'contrat-prestation-aes256.pdf' : 'service-contract-aes256.pdf' ), ), 'invoice' => array( 'label' => __( 'Invoice', 'vefdocskit' ), 'text' => __( 'Not protected.', 'vefdocskit' ), 'pages' => 2, 'name' => $french ? 'facture-exemple.pdf' : 'sample-invoice.pdf', 'path' => $dir . ( $french ? 'facture-exemple.pdf' : 'sample-invoice.pdf' ), ), ); /** * The sample documents offered to a visitor of the tools (identifier => label, text, pages, name, path). * * @param array> $list Samples. */ $list = apply_filters( 'vefdk_sample_documents', $list ); return is_array( $list ) ? $list : array(); } /** * One sample, when it exists and its file can be read. * * @param string $id Identifier. * @return array|null */ public static function get( $id ) { $list = self::all(); $id = (string) $id; if ( ! isset( $list[ $id ] ) || ! is_array( $list[ $id ] ) ) { return null; } $path = (string) ( $list[ $id ]['path'] ?? '' ); return ( '' !== $path && is_readable( $path ) ) ? $list[ $id ] : null; } /** * What the screen needs to show the samples (never the paths). * * @return array> */ public static function for_screen() { $out = array(); foreach ( array_keys( self::all() ) as $id ) { $sample = self::get( $id ); if ( $sample ) { $out[] = array( 'id' => (string) $id, 'label' => (string) ( $sample['label'] ?? $id ), 'text' => (string) ( $sample['text'] ?? '' ), 'pages' => (int) ( $sample['pages'] ?? 0 ), ); } } return $out; } /** * The files of a request, as the tools expect them. Null when one identifier is unknown. * * @param mixed $ids Identifiers. * @return array|null */ public static function files( $ids ) { if ( ! is_array( $ids ) || ! $ids || count( $ids ) > self::MAX ) { return null; } $files = array(); foreach ( $ids as $id ) { $sample = is_string( $id ) ? self::get( $id ) : null; if ( ! $sample ) { return null; } $files[] = array( 'name' => (string) ( $sample['name'] ?? basename( (string) $sample['path'] ) ), 'path' => (string) $sample['path'], 'password' => '', ); } return $files; } }