gde_validate_file
Test for valid shortcode syntax, other file errors.
Description
Returns (string)
Error message (if any)
Parameters (2)
- 0. $file
- The file.
- 1. $force
- The force.
Usage
if ( !function_exists( 'gde_validate_file' ) ) { require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; } // The file. $file = null; // The force. $force = null; // NOTICE! Understand what this does before running. $result = gde_validate_file($file, $force);
Defined (1)
The function is defined in the following location(s).
- /functions.php
- function gde_validate_file( $file = NULL, $force ) {
- //errormessages
- $nofile = __('File not specified, check shortcode syntax', 'google-document-embedder');
- $badlink = __('Requested URL is invalid', 'google-document-embedder');
- $badtype = __('Unsupported File Type', 'google-document-embedder') . " (%e)";
- $unktype = __('Unable to determine file type from URL', 'google-document-embedder');
- $notfound = __('Error retrieving file - if necessary turn offerrorchecking', 'google-document-embedder') . " (%e)";
- if ( ! $file ) {
- return $nofile;
- }
- $result = gde_valid_url( $file );
- if ( $result === false ) {
- // validation skipped due to service failure
- return -1;
- } elseif ( $force == "1" || $force == "yes" ) {
- if ( is_array( $result ) ) {
- return $result;
- } else {
- // couldn't get file size due to service failure
- return -1;
- }
- } elseif ( ! $result ) {
- // can't validate
- return -1;
- } else {
- if ( isset( $result['code'] ) && $result['code'] != 200 ) {
- if ( ! gde_valid_link( $file ) ) {
- return $badlink;
- } else {
- $err = $result['code'] . ":" . $result['message'];
- $notfound = str_replace( "%e", $err, $notfound );
- return $notfound;
- }
- } else {
- if ( ! gde_valid_type( $file ) ) {
- $fn = basename( $file );
- $fnp = gde_split_filename( $fn );
- $type = $fnp[1];
- if ( $type == '' ) {
- return $unktype;
- }
- $badtype = str_replace( "%e", $type, $badtype );
- return $badtype;
- } else {
- return $result;
- }
- }
- }
- }