Ejemplo n.º 1
0
/**
 * Modify the file insertion from Media Library if requested
 *
 * @since   2.4.0.1
 * @note	Requires WP 3.5+
 * @return  string HTML to insert into editor
 */
function gde_media_insert($html, $id, $attachment)
{
    global $gdeoptions;
    $gdoc_url = '';
    if (isset($attachment['url'])) {
        $gdoc_url = $attachment['url'];
    } elseif ($id > 0) {
        $post = get_post($id);
        if ($post) {
            $gdoc_url = wp_get_attachment_url($id);
        }
    }
    if ($gdoc_url != '' && gde_valid_type($gdoc_url) && $gdeoptions['ed_embed_sc'] == "yes") {
        return '[gview file="' . $gdoc_url . '"]';
    } else {
        return $html;
    }
}
Ejemplo n.º 2
0
/**
 * Test for valid shortcode syntax, other file errors
 *
 * @return  string Error message (if any)
 */
function gde_validate_file($file = NULL, $force)
{
    // error messages
    $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 off error checking', '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;
            }
        }
    }
}
/**
 * Modify the file insertion from Media Library if requested
 *
 * @since   2.4.0.1
 * @note	Requires WP 3.5+
 * @return  string HTML to insert into editor
 */
function gde_media_insert($html, $id, $attachment)
{
    global $gdeoptions;
    if (gde_valid_type($attachment['url']) && $gdeoptions['ed_embed_sc'] == "yes") {
        return '[gview file="' . $attachment['url'] . '"]';
    } else {
        return $html;
    }
}