<?php
$gde_ver = "2.6.2";
$gde_db_ver = "1.2";
require_once( plugin_dir_path( __FILE__ ) . 'functions.php' );
global $wp_version;
$pdata = gde_get_plugin_data();
$gdeoptions = get_option( 'gde_options' );
$gdetypes = gde_supported_types();
$healthy = gde_debug_tables();
if ( is_admin() ) { require_once( GDE_PLUGIN_DIR . 'functions-admin.php' ); }
register_activation_hook( __FILE__, 'gde_activate' );
register_deactivation_hook( __FILE__, 'gde_deactivate' );
add_action( 'plugins_loaded', 'gde_load' );
add_shortcode( 'gview', 'gde_do_shortcode' );
function gde_do_shortcode( $atts ) {
global $healthy, $gdeoptions;
if ( ! $healthy ) {
delete_option('gde_db_version');
return gde_show_error( __('Unable to load profile settings', 'google-document-embedder') );
}
extract( shortcode_atts( array (
'file' => '',
'profile' => 1,
'save' => '',
'width' => '',
'height' => '',
'cache' => ''
), $atts ) );
$term = $profile;
if ( is_numeric( $term ) ) {
if ( ! $profile = gde_get_profiles( $term ) ) {
gde_dx_log("Loading default profile instead");
if ( ! $profile = gde_get_profiles( 1 ) ) {
return gde_show_error( __('Unable to load requested profile.', 'google-document-embedder') );
} else {
$pid = 1;
}
} else {
$pid = $term;
}
} else {
if ( ! $profile = gde_get_profiles( strtolower( $term ) ) ) {
gde_dx_log("Loading default profile instead");
if ( ! $profile = gde_get_profiles( 1 ) ) {
return gde_show_error( __('Unable to load requested profile.', 'google-document-embedder') );
} else {
$pid = 1;
}
} else {
$pid = $profile['profile_id'];
}
}
if ( $save !== "0" ) {
if ( empty( $save ) ) {
$save = $profile['link_show'];
}
}
if ( empty( $width ) ) {
$width = $profile['default_width'];
}
if ( empty( $height ) ) {
$height = $profile['default_height'];
}
if ( $cache !== "0" ) {
if ( empty( $cache ) ) {
$cache = $profile['cache'];
}
}
$lang = $profile['language'];
$width = gde_sanitize_dims( $width );
$height = gde_sanitize_dims( $height );
if ( ! preg_match( "/^http/i", $file ) ) {
if ( substr( $file, 0, 2 ) == "
if ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ) {
$file = "https:" . $file;
} else {
$file = "http:" . $file;
}
} elseif ( isset( $profile['base_url'] ) ) {
if ( substr( $file, 0, 1 ) == "/" ) {
$file = ltrim( $file, '/' );
}
$file = $profile['base_url'] . $file;
}
}
$fn = basename( $file );
$fnp = gde_split_filename( $fn );
if ( ! $file ) {
return gde_show_error( __('File not specified, check shortcode syntax', 'google-document-embedder') );
}
if ( $gdeoptions['error_check'] == "no" ) {
$force = true;
} else {
$force = false;
}
$status = gde_validate_file( str_replace( " ", "%20", $file ), $force );
if ( ! isset( $code ) && ! is_array( $status ) && $status !== -1 ) {
$code = gde_show_error( $status );
} elseif ( ! isset( $code ) ) {
$viewer = true;
if ( $gdeoptions['file_maxsize'] > 0 && isset( $status['fsize'] ) ) {
$maxbytes = (int) $gdeoptions['file_maxsize'] * 1024 * 1024;
if ( $status['fsize'] > $maxbytes ) {
$viewer = false;
}
}
$links = array( $file, $file );
if ( $profile['link_block'] == "yes" && gde_is_blockable( $profile ) ) {
if ( $secure = gde_get_secure_url( $file ) ) {
$links[0] = $secure;
} else {
$links[0] = '';
}
$links[1] = '';
} elseif ( $profile['link_show'] !== "none" ) {
if ( $profile['link_force'] == "yes" && $profile['link_mask'] == "no" ) {
$links[1] = GDE_PLUGIN_URL . "load.php?d=" . urlencode( $links[1] );
} elseif ( $profile['link_force'] == "no" && $profile['link_mask'] == "yes" ) {
$short = gde_get_short_url( $links[0] );
$links[0] = $short;
$links[1] = $short;
} elseif ( $profile['link_force'] == "yes" && $profile['link_mask'] == "yes" ) {
$short = gde_get_short_url( GDE_PLUGIN_URL . "load.php?d=" . urlencode( $links[0] ) );
$links[0] = $short;
$links[1] = $short;
}
}
if ( ! empty( $links[1] ) && ( $cache == "off" || $cache == "0" ) ) {
$links[0] .= "?" . time();
}
if ( empty( $links[0] ) && empty( $links[1] ) ) {
$code = gde_show_error( __('Unable to secure document', 'google-document-embedder') );
} else {
else {
$lnk = "
else {
$lnk .= "&embedded=true";
if ( $viewer == false ) {
$vwr = '';
} else {
$vwr = '<iframe src="%U%" class="gde-frame" style="width:%W%; height:%H%; border: none;"%ATTRS%></iframe>';
$vwr = str_replace("%U%", $lnk, $vwr);
$vwr = str_replace("%W%", $width, $vwr);
$vwr = str_replace("%H%", $height, $vwr);
$vattr[] = ' scrolling="no"';
$vwr = str_replace( "%ATTRS%", implode( '', $vattr ), $vwr );
}
$allow_save = false;
if ( ! empty( $links[1] ) ) {
if ( $save == "all" || $save == "1" ) {
$allow_save = true;
} elseif ( $save == "users" && is_user_logged_in() ) {
$allow_save = true;
}
}
if ( $allow_save ) {
$linkcode = '<p class="gde-text"><a href="%LINK%" class="gde-link"%ATTRS%>%TXT%</a></p>';
$linkcode = str_replace( "%LINK%", $links[1], $linkcode );
$ftype = strtoupper( $fnp[1] );
if ( $ftype == "TIF" ) {
$ftype = "TIFF";
}
if ( $profile['link_mask'] == "yes" ) {
$attr[] = ' rel="nofollow"';
}
$attr[] = gde_ga_event( $file );
$linkcode = str_replace("%ATTRS%", implode( '', $attr ), $linkcode);
if ( empty( $profile['link_text'] ) ) {
$profile['link_text'] = __('Download', 'google-document-embedder');
}
$dltext = str_replace( "%FILE", $fn, $profile['link_text'] );
$dltext = str_replace( "%TYPE", $ftype, $dltext );
$dltext = str_replace( "%SIZE", gde_format_bytes( $status['fsize'] ), $dltext );
$linkcode = str_replace( "%TXT%", $dltext, $linkcode );
} else {
$linkcode = '';
}
if ( $profile['link_pos'] == "above" ) {
$code = $linkcode . "\n" . $vwr;
} else {
$code = $vwr . "\n" . $linkcode;
}
}
}
return $code;
}
if ( is_admin() ) {
add_filter( "plugin_action_links_" . plugin_basename( __FILE__ ), 'gde_actlinks' );
add_action( 'after_plugin_row', 'gde_warn_on_plugin_page' );
if ( ! isset( $gdeoptions['ed_disable'] ) || $gdeoptions['ed_disable'] == "no" ) {
add_action( 'admin_print_scripts', 'gde_admin_print_scripts' );
add_action( 'admin_init', 'gde_mce_addbuttons' );
if ( $gdeoptions['ed_extend_upload'] == "yes" ) {
add_filter( 'upload_mimes', 'gde_upload_mimes' );
}
add_filter( 'media_send_to_editor', 'gde_media_insert', 20, 3 );
}
add_action( 'admin_menu', 'gde_option_page' );
}
function gde_activate( $network_wide ) {
if ( ! ( phpversion() >= '5.2.0' ) ) {
wp_die( 'Your server is running PHP version ' . phpversion() . ' but this plugin requires at least 5.2.0' );
}
$gde_db_ver = "1.2";
if ( $network_wide ) {
wp_die("Network activation is not supported at this time. Please activate individually until an update is available.");
}
require_once( plugin_dir_path( __FILE__ ) . 'libs/lib-setup.php' );
if ( gde_db_tables( $gde_db_ver ) ) {
gde_setup();
} else {
gde_dx_log("Table creation failed; setup halted");
wp_die( __("Setup wasn't able to create the required database tables.", 'google-document-embedder') );
}
}
function gde_deactivate() {
global $wpdb;
$table = $wpdb->base_prefix . 'gde_dx_log';
if ( is_multisite() ) {
$blogid = get_current_blog_id();
$wpdb->query("DELETE FROM $table WHERE blogid = '$blogid'");
} else {
$wpdb->query("DROP TABLE IF EXISTS $table");
}
}
function gde_load() {
load_plugin_textdomain( 'google-document-embedder', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
?>