/** * Create/update profile * * @since 2.5.0.1 * @return int 0 = fail, 1 = created, 2 = updated, 3 = nothing to do * @note data array expected: [0] name, [1] desc, [2] serialized data */ function gde_write_profile($data, $id = null, $overwrite = false) { global $wpdb; $table = $wpdb->prefix . 'gde_profiles'; if (empty($id)) { // get profile name $pname = strtolower($data[0]); // new (non-default) profile if (!$wpdb->insert($table, array('profile_name' => $pname, 'profile_desc' => $data[1], 'profile_data' => $data[2]))) { gde_dx_log("Failed to create profile '{$pname}'"); return 0; } else { gde_dx_log("New profile '{$pname}' created"); return 1; } } else { // new (default) or updated profile if (is_null($wpdb->get_row("SELECT * FROM {$table} WHERE profile_id = {$id}"))) { // new default profile //gde_dx_log("Profile ID $id doesn't exist - creating"); if (!$wpdb->insert($table, array('profile_id' => $id, 'profile_name' => strtolower($data[0]), 'profile_desc' => $data[1], 'profile_data' => $data[2]), array('%d', '%s', '%s', '%s'))) { gde_dx_log("Profile {$id} creation failed"); return 0; } else { gde_dx_log("Profile {$id} created"); return 1; } } elseif ($overwrite) { // get old data $olddata = gde_get_profiles($id, false, true); $olddesc = $olddata['profile_desc']; unset($olddata['profile_desc']); // update profile gde_dx_log("Profile ID {$id} exists - updating"); if (!empty($data[0])) { // overwrite name $newdata['profile_name'] = strtolower($data[0]); } if (!empty($data[1]) && $data[1] !== $olddesc) { // overwrite description $newdata['profile_desc'] = $data[1]; } if (!empty($data[2]) && $data[2] !== serialize($olddata)) { // overwrite data $newdata['profile_data'] = $data[2]; } if (isset($newdata)) { if (!$wpdb->update($table, $newdata, array('profile_id' => $id), array('%s', '%s', '%s'))) { $info = print_r($newdata, true); gde_dx_log("Profile {$id} update failed writing: \n\n {$info}"); return 0; } else { gde_dx_log("Profile {$id} updated"); return 2; } } else { gde_dx_log("Overwrite requested but no changes found"); return 3; } } else { gde_dx_log("Profile {$id} exists, overwrite not specified - nothing changed"); return 3; } } }
/** * Upgrade profiles if changes have been made * * @since 2.5.5.1 * @return void */ function update_profiles() { $prodata = gde_get_profiles(); $defpros = gde_defaults('profiles'); $default = $defpros['default']; foreach ($prodata as $profile) { $updated = false; $id = $profile['profile_id']; if ($data = @unserialize($profile['profile_data'])) { foreach ($default as $k => $v) { if ($k !== "desc" && !array_key_exists($k, $data)) { $data[$k] = $default[$k]; $updated = true; } } if ($updated) { // write updated profile $data = serialize($data); $newpro = array($profile['profile_name'], $profile['profile_desc'], $data); if (gde_write_profile($newpro, $id, true) < 1) { gde_dx_log("Failed to update profile '" . $profile['profile_name'] . "'"); } } } } }
function gde_profile_form($id = 1) { global $healthy; // get requested profile if (!$healthy) { echo "<p>" . gde_show_error(__('Unable to load profile settings. Please re-activate GDE and if the problem persists, request help using the "Support" tab.', 'google-document-embedder')) . "</p>\n"; } else { $p = gde_get_profiles($id); // minimize FOUC if ($p['viewer'] == "standard") { $hideenh = " hide"; } else { $hideenh = ''; } // setup title & nonce if ($id == 1) { $title = __('Default Settings', 'google-document-embedder'); $desc = __('These settings define the default viewer profile, which is used when no other profile is specified.', 'google-document-embedder'); $naction = "update-default-opts"; $nname = "_general_default"; } else { $title = __('Edit Profile', 'google-document-embedder'); $naction = "update-profile-opts"; $nname = "_profile_edit"; } ?> <div id="profile-form"> <form action="" method="post"> <?php wp_nonce_field($naction, $nname); ?> <input type="hidden" name="profile_id" value="<?php echo esc_attr($id); ?> "> <?php gde_help_link(GDE_STDOPT_URL, 'right'); ?> <h3><?php echo $title; ?> </h3> <?php if (isset($desc)) { echo htmlentities($desc); } ?> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><?php _e('Viewer Mode', 'google-document-embedder'); ?> </th> <td> <select name="viewer" id="viewer"> <?php gde_profile_option($p['viewer'], 'standard', __('Standard Viewer', 'google-document-embedder'), __('Embed the basic viewer only', 'google-document-embedder')); //gde_profile_option( $p['viewer'], 'enhanced', __('Enhanced Viewer', 'google-document-embedder'), __('Enable extended viewer options', 'google-document-embedder') ); ?> </select><br/> <span class="gde-fnote" id="viewer-h"></span> <p><b>To find out why Enhanced Mode is no longer available, see the notice on our <a href="https://wordpress.org/plugins/google-document-embedder/" target="_blank">plugin homepage</a>. </b></p> </td> </tr> </tbody> </table> <!-- <fieldset class="gde-inner<?php echo $hideenh; ?> " id="gde-enh-fs"> <legend><?php _e('Enhanced Viewer Settings', 'google-document-embedder'); ?> </legend> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><?php _e('Toolbar', 'google-document-embedder'); ?> </th> <td> <?php gde_help_link(GDE_ENHOPT_URL, 'right'); gde_profile_checkbox($p['tb_flags'], 'gdet_h', __('Remove Toolbar', 'google-document-embedder')); ?> </td> </tr> <tr valign="top" id="mobiletb"> <th scope="row"><?php _e('Use Mobile Toolbar', 'google-document-embedder'); ?> </th> <td> <select name="tb_mobile" id="tb_mobile"> <?php gde_profile_option($p['tb_mobile'], 'default', __('Mobile Devices Only (Default)', 'google-document-embedder'), __('Use mobile toolbar when mobile device detected', 'google-document-embedder')); gde_profile_option($p['tb_mobile'], 'always', __('Always', 'google-document-embedder'), __('Use mobile toolbar for all visitors', 'google-document-embedder')); gde_profile_option($p['tb_mobile'], 'never', __('Never', 'google-document-embedder'), __('Never use mobile toolbar', 'google-document-embedder')); ?> </select><br/> <span class="gde-fnote" id="mobile-h"></span> </td> </tr> <tr valign="top" id="toolbuttons"> <th scope="row"><?php _e('Toolbar Items', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_checkbox($p['tb_flags'], 'gdet_p', __('Page Numbers', 'google-document-embedder')); gde_profile_checkbox($p['tb_flags'], 'gdet_r', __('Previous/Next Page', 'google-document-embedder')); gde_profile_checkbox($p['tb_flags'], 'gdet_z', __('Zoom In/Out', 'google-document-embedder')); gde_profile_checkbox($p['tb_flags'], 'gdet_n', __('Full Screen/New Window', 'google-document-embedder'), 'allowNewWin'); ?> <br/> <span class="gde-fnote"><?php _e('Uncheck items to remove from toolbar. Buttons will vary based on file type and device used.', 'google-document-embedder'); ?> </span> </td> </tr> <tr valign="top" id="fullscreen"> <th scope="row"><?php _e('Full Screen Behavior', 'google-document-embedder'); ?> </th> <td> <select name="tb_fullscr" id="tb_fullscr"> <?php gde_profile_option($p['tb_fullscr'], 'default', __('Google-Hosted Page (Default)', 'google-document-embedder')); //gde_profile_option( $p['tb_fullscr'], 'branded', __('Custom-Branded Page', 'google-document-embedder') ); gde_profile_option($p['tb_fullscr'], 'viewer', __('Full Screen Viewer', 'google-document-embedder')); ?> </select><br/> <?php gde_profile_checkbox($p['tb_fullwin'], 'fs_win', __('Open in New Window', 'google-document-embedder')); gde_profile_checkbox($p['tb_fulluser'], 'fs_user', __('Allow Logged-in Users Only', 'google-document-embedder'), 'blockAnon'); //gde_profile_checkbox( $p['tb_print'], 'fs_print', __('Allow Printing', 'google-document-embedder'), 'allowPrint' ); ?> </td> </tr> <tr valign="top" id="bgcolor"> <th scope="row"><?php _e('Page Area Background Color', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_text($p['vw_bgcolor'], 'vw_bgcolor', 'gde-color-field', 10); gde_profile_checkbox($p['vw_flags'], 'gdev_t', __('None (Transparent)', 'google-document-embedder')); ?> </td> </tr> <tr valign="top" id="pbcolor"> <th scope="row"><?php _e('Page Border Color', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_text($p['vw_pbcolor'], 'vw_pbcolor', 'gde-color-field', 10); gde_profile_checkbox($p['vw_flags'], 'gdev_b', __('No Border', 'google-document-embedder')); ?> </td> </tr> <tr valign="top" id="cssfile"> <th scope="row"><?php _e('Custom CSS File', 'google-document-embedder'); ?> </th> <td> <?php @gde_profile_text($p['vw_css'], 'vw_css', '', '65'); ?> <br/> <span class="gde-fnote"><?php _e('URL of custom CSS file (may override some of the above options)', 'google-document-embedder'); ?> </span> </td> </tr> <tr valign="top" id="docsec"> <th scope="row"><?php _e('Security', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_checkbox($p['vw_flags'], 'gdev_x', __('Hide ability to select/copy/paste text', 'google-document-embedder'), 'hideselect', 1); gde_profile_checkbox($p['link_block'], 'block', __('Block all download requests for file', 'google-document-embedder'), 'linkblock', 1); ?> </td> </tr> </tbody> </table> </fieldset> --> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><?php _e('Default Language', 'google-document-embedder'); ?> </th> <td> <select name="language" id="language"> <?php require_once GDE_PLUGIN_DIR . 'libs/lib-langs.php'; $langs = gde_supported_langs(); foreach ($langs as $code => $desc) { gde_profile_option($p['language'], $code, $desc); } ?> </select><br/> <span class="gde-fnote"><?php _e('Language of toolbar button tips', 'google-document-embedder'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Default Size', 'google-document-embedder'); ?> </th> <td> <?php _e('Width', 'google-document-embedder'); ?> <?php gde_profile_text($p['default_width'], 'default_width', '', '5'); ?> <?php _e('Height', 'google-document-embedder'); ?> <?php gde_profile_text($p['default_height'], 'default_height', '', '5'); ?> <br/> <span class="gde-fnote"><?php _e('Enter as pixels or percentage (example: 500px or 100%)', 'google-document-embedder'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('File Base URL', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_text($p['base_url'], 'base_url', '', '65'); ?> <br/> <span class="gde-fnote"><?php _e('Any file not starting with <code>http</code> will be prefixed by this value', 'google-document-embedder'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Download Link', 'google-document-embedder'); ?> </th> <td> <select name="link_show" id="link_show"> <?php gde_profile_option($p['link_show'], 'all', __('All Users', 'google-document-embedder'), __('Download link visible to everyone by default', 'google-document-embedder')); gde_profile_option($p['link_show'], 'users', __('Logged-in Users', 'google-document-embedder'), __('Download link visible to logged-in users', 'google-document-embedder')); gde_profile_option($p['link_show'], 'none', __('None', 'google-document-embedder'), __('Download link is not visible by default', 'google-document-embedder')); ?> </select><br/> <span class="gde-fnote" id="linkshow-h"></span> </td> </tr> <tr valign="top" id="linktext"> <th scope="row"><?php _e('Link Text', 'google-document-embedder'); ?> </th> <td> <input size="50" name="link_text" value="<?php echo esc_attr($p['link_text']); ?> " type="text"><br/> <span class="gde-fnote"><?php _e('You can further customize text using these dynamic replacements:', 'google-document-embedder'); ?> </span><br> <code>%FILE</code> : <?php _e('filename', 'google-document-embedder'); ?> <code>%TYPE</code> : <?php _e('file type', 'google-document-embedder'); ?> <code>%SIZE</code> : <?php _e('file size', 'google-document-embedder'); ?> </td> </tr> <tr valign="top" id="linkpos"> <th scope="row"><?php _e('Link Position', 'google-document-embedder'); ?> </th> <td> <select name="link_pos"> <?php gde_profile_option($p['link_pos'], 'above', __('Above Viewer', 'google-document-embedder')); gde_profile_option($p['link_pos'], 'below', __('Below Viewer', 'google-document-embedder')); ?> </select> </td> </tr> <tr valign="top" id="linkbehavior"> <th scope="row"><?php _e('Link Behavior', 'google-document-embedder'); ?> </th> <td> <?php gde_profile_checkbox($p['link_force'], 'force', __('Force download (bypass browser plugins)', 'google-document-embedder'), 'linkforce', 1); //gde_profile_checkbox( $p['link_mask'], 'mask', __('Shorten URL', 'google-document-embedder'), 'linkmask', 1 ); ?> </td> </tr> </tbody> </table> <p class="gde-submit"> <input id="pro-submit" class="button-primary" type="submit" value="<?php _e('Save Changes', 'google-document-embedder'); ?> " name="submit"> </p> </form> </div> <?php } }
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; }
} else { gde_output_json(json_encode($profiles)); } } else { echo "0"; exit; } case "settings": if (isset($_REQUEST['save']) && $_REQUEST['save'] == "1") { $file = 'gde-settings'; gde_output_json(json_encode($gdeoptions), true, $file); } else { gde_output_json(json_encode($gdeoptions)); } case "all": $data['profiles'] = gde_get_profiles(); $data['settings'] = $gdeoptions; if (isset($_REQUEST['save']) && $_REQUEST['save'] == "1") { unset($data['settings']['api_key']); $file = 'gde-export'; gde_output_json(json_encode($data), true, $file); } else { gde_output_json(json_encode($data)); } default: wp_die('<p>' . __('You do not have sufficient permissions to access this page.') . '</p>'); } } elseif (isset($_REQUEST['viewlog'])) { // request to view dx log global $wpdb; $blogid = get_current_blog_id();
<?php // make it work with localization (ie cyrillic languages) header('Content-type: text/html; charset=UTF-8'); // access wp functions externally require_once dirname(__FILE__) . '/lib-bootstrap.php'; // no access if parent plugin is disabled if (!function_exists('gde_do_shortcode')) { wp_die(__('Access denied.', 'google-document-embedder')); } // get profiles $profiles = gde_get_profiles(); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Google Doc Embedder</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script language="javascript" type="text/javascript" src="<?php echo includes_url(); ?> js/tinymce/tiny_mce_popup.js"></script> <script language="javascript" type="text/javascript" src="<?php echo includes_url(); ?> js/jquery/jquery.js"></script> <script type="text/javascript" src="../js/dialog.js"></script> <style type="text/css"> * { font-family: Arial, Helvetica, sans-serif !important;