/** * Google Analytics Integration * * @since 2.5.0.1 * @return string GA tracking event tag, or blank if disabled */ function gde_ga_event($file) { global $gdeoptions; if ($gdeoptions['ga_enable'] == "no") { return ''; } elseif ($gdeoptions['ga_enable'] == "compat") { $fnp = gde_split_filename(basename($file)); $category = "'Download'"; // intentionally not translated (it wasn't a translated string in < 2.5) $action = "'" . strtoupper($fnp[1]) . "'"; $label = "this.href"; } else { $category = "'" . addslashes($gdeoptions['ga_category']) . "'"; $action = "'" . __('Download', 'google-document-embedder') . "'"; if ($gdeoptions['ga_label'] == "url") { $label = "this.href"; } else { $label = "'" . basename($file) . "'"; } } $str = "_gaq.push(['_trackEvent', " . $category . ", " . $action . ", " . $label . "]);"; return " onClick=\"" . $str . "\""; }
function gde_do_shortcode($atts) { global $healthy, $gdeoptions; //$gdeglobals // check profile table health if (!$healthy) { delete_option('gde_db_version'); return gde_show_error(__('Unable to load profile settings', 'google-document-embedder')); } // handle global setting overrides - not active in this release /* if ($gdeglobals['enforce_viewer'] == "std") { $gdeoptions['disable_proxy'] = "yes"; } if ($gdeglobals['enforce_lang']) { $gdeoptions['default_lang'] = $gdeglobals['enforce_lang']; } */ extract(shortcode_atts(array('file' => '', 'profile' => 1, 'save' => '', 'width' => '', 'height' => '', 'cache' => ''), $atts)); // get requested profile data (or default if doesn't exist) $term = $profile; if (is_numeric($term)) { // id-based lookup 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 { // name-based lookup 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']; } } // use profile defaults if shortcode override not defined 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']; } } //if ( $profile['language'] !== "en_US" ) { $lang = $profile['language']; //} // tweak the dimensions if necessary $width = gde_sanitize_dims($width); $height = gde_sanitize_dims($height); // add base url if needed if (!preg_match("/^http/i", $file)) { if (substr($file, 0, 2) == "//") { // append dynamic protocol if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $file = "https:" . $file; } else { $file = "http:" . $file; } } elseif (isset($profile['base_url'])) { // not a full link, add base URL if available if (substr($file, 0, 1) == "/") { // remove any preceding slash from doc (base URL adds it) $file = ltrim($file, '/'); } $file = $profile['base_url'] . $file; } } // capture file details $fn = basename($file); $fnp = gde_split_filename($fn); // check for missing required field if (!$file) { return gde_show_error(__('File not specified, check shortcode syntax', 'google-document-embedder')); } // file validation 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) { // validation failed $code = gde_show_error($status); } elseif (!isset($code)) { // validation passed or was skipped // check for max filesize $viewer = true; if ($gdeoptions['file_maxsize'] > 0 && isset($status['fsize'])) { $maxbytes = (int) $gdeoptions['file_maxsize'] * 1024 * 1024; if ($status['fsize'] > $maxbytes) { $viewer = false; } } // generate links (embed, download) $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; } } // obfuscate filename if cache disabled (globally or via shortcode) // note that this is ignored if the document is secure to prevent each hit from generating a new db row if (!empty($links[1]) && ($cache == "off" || $cache == "0")) { $links[0] .= "?" . time(); } // check for failed secure doc if (empty($links[0]) && empty($links[1])) { $code = gde_show_error(__('Unable to secure document', 'google-document-embedder')); } else { // which viewer? //if ( $profile['viewer'] == "enhanced" ) { // $lnk = GDE_PLUGIN_URL . "view.php?url=" . urlencode( $links[0] ) . "&hl=" . $lang . "&gpid=" . $pid; // make protocol-agnostic // $lnk = preg_replace( '/^https?:/i', '', $lnk ); //} else { $lnk = "//docs.google.com/viewer?url=" . urlencode($links[0]) . "&hl=" . $lang; //} // what mode? //if ( $profile['tb_mobile'] == "always" ) { // $lnk .= "&mobile=true"; //} else { $lnk .= "&embedded=true"; //} // build viewer if ($viewer == false) { // exceeds max filesize $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); // frame attributes $vattr[] = ' scrolling="no"'; // iphone scrolling bug //if ( ! empty( $page ) && is_numeric( $page ) ) { // selected starting page // $page = (int) $page - 1; // $vattr[] = ' onload="javascript:this.contentWindow.location.hash=\':0.page.' . $page . '\';"'; //} $vwr = str_replace("%ATTRS%", implode('', $vattr), $vwr); } // show download link? $allow_save = false; if (!empty($links[1])) { // link empty = secure document; ignore any other save attribute if ($save == "all" || $save == "1") { $allow_save = true; } elseif ($save == "users" && is_user_logged_in()) { $allow_save = true; } } if ($allow_save) { // build download link $linkcode = '<p class="gde-text"><a href="%LINK%" class="gde-link"%ATTRS%>%TXT%</a></p>'; $linkcode = str_replace("%LINK%", $links[1], $linkcode); // fix type $ftype = strtoupper($fnp[1]); if ($ftype == "TIF") { $ftype = "TIFF"; } // link attributes if ($profile['link_mask'] == "yes") { $attr[] = ' rel="nofollow"'; } $attr[] = gde_ga_event($file); // GA integration $linkcode = str_replace("%ATTRS%", implode('', $attr), $linkcode); // link text 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 = ''; } // link position if ($profile['link_pos'] == "above") { $code = $linkcode . "\n" . $vwr; } else { $code = $vwr . "\n" . $linkcode; } } } return $code; }