Example #1
0
/**
 * Generate and store secure document link
 *
 * @since	2.5.0.3
 * @return  string Secure document link or false on failure
 */
function gde_make_secure_url($url)
{
    global $wpdb;
    $table = $wpdb->prefix . 'gde_secure';
    $data = $wpdb->get_results("SELECT * FROM {$table} WHERE url = '{$url}'", ARRAY_A);
    if (!empty($data)) {
        // a secure url to this doc already exists
        $data = $data[0];
        return $data['murl'];
    } else {
        // make a new entry
        $newcode = gde_secure_code();
        $url_to_mask = GDE_PLUGIN_URL . "load.php?s=" . $newcode;
        $masked_url = gde_get_short_url($url_to_mask);
        if (!$wpdb->insert($table, array('code' => $newcode, 'url' => $url, 'murl' => $masked_url), array('%s', '%s', '%s'))) {
            gde_dx_log("Unable to record secure URL in database");
            return false;
        } else {
            return $masked_url;
        }
    }
}
/**
 * Check health of database tables
 *
 * @since   2.5.0.3
 * @return  mixed
 * @note	Verbose text used in debug information
 */
function gde_debug_tables($table = array('gde_profiles', 'gde_secure'), $verbose = false)
{
    global $wpdb;
    if (is_array($table)) {
        $ok = true;
        foreach ($table as $t) {
            $t = $wpdb->prefix . $t;
            if ($wpdb->get_var("SHOW TABLES LIKE '{$t}'") == $t) {
                // table good
            } else {
                $ok = false;
                gde_dx_log($t . " table missing");
                break;
            }
        }
    } else {
        $ok = true;
        $table = $wpdb->prefix . $table;
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") == $table) {
            $s = "OK ";
            $c = $wpdb->get_var("SELECT COUNT(*) FROM {$table} WHERE 1=1");
            $s = $s . "({$c} items)";
        } else {
            $s = "NOT OK ({$table} missing)";
            $ok = false;
        }
    }
    if (!$verbose) {
        return $ok;
    } else {
        return $s;
    }
}
Example #3
0
function gde_import_profiles($data)
{
    $success = 0;
    foreach ($data as $v) {
        $pid = gde_profile_name_exists($v['profile_name']);
        if ($pid !== -1) {
            // overwrite existing profile
            $prodata = array('', $v['profile_desc'], $v['profile_data']);
            if (gde_write_profile($prodata, $pid, true) > 0) {
                $success++;
            } else {
                gde_dx_log("failure importing to overwrite profile {$pid}");
            }
        } else {
            // write as new profile
            $prodata = array($v['profile_name'], $v['profile_desc'], $v['profile_data']);
            if (gde_write_profile($prodata) > 0) {
                $success++;
            } else {
                gde_dx_log("failure importing to new profile");
            }
        }
    }
    return $success;
}
/**
 * Create/update database table to store profile data
 *
 * @since   2.5.0.1
 * @return  bool Whether or not table creation/update was successful
 */
function gde_db_tables($gde_db_ver)
{
    global $wpdb;
    // attempt to trap table creation failures
    $fails = 0;
    // check for missing required tables (clear db version)
    $table = $wpdb->prefix . 'gde_profiles';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") !== $table) {
        //gde_dx_log("profiles db failed health check");
        delete_site_option('gde_db_version');
    }
    $table = $wpdb->prefix . 'gde_secure';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") !== $table) {
        //gde_dx_log("securedoc db failed health check");
        delete_site_option('gde_db_version');
    }
    if (is_multisite()) {
        $db_ver_installed = get_site_option('gde_db_version', 0);
    } else {
        $db_ver_installed = get_option('gde_db_version', 0);
    }
    gde_dx_log("Installed DB ver: {$db_ver_installed}; This DB ver: " . $gde_db_ver);
    if (version_compare($gde_db_ver, $db_ver_installed, ">")) {
        // install or upgrade profile table
        $table = $wpdb->prefix . 'gde_profiles';
        $sql = "CREATE TABLE " . $table . " (\r\n\t\t  profile_id mediumint(9) UNSIGNED NOT NULL AUTO_INCREMENT,\r\n\t\t  profile_name varchar(64) NOT NULL,\r\n\t\t  profile_desc varchar(255) NULL,\r\n\t\t  profile_data longtext NOT NULL,\r\n\t\t  UNIQUE KEY (profile_id)\r\n\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8; ";
        if (isset($sql)) {
            // write table or update to database
            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            dbDelta($sql);
            if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") == $table) {
                gde_dx_log("Profile table create/update successful");
            } else {
                gde_dx_log("Profile table create/update failed");
                $fails++;
            }
        }
        // install or upgrade securedoc table
        $table = $wpdb->prefix . 'gde_secure';
        $sql = "CREATE TABLE " . $table . " (\r\n\t\t  code varchar(10) NOT NULL,\r\n\t\t  url varchar(255) NOT NULL,\r\n\t\t  murl varchar(100) NOT NULL,\r\n\t\t  stamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t  autoexpire enum('Y','N') NOT NULL DEFAULT 'N',\r\n\t\t  UNIQUE KEY code (code)\r\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8; ";
        if (isset($sql)) {
            // write table or update to database
            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            dbDelta($sql);
            if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") == $table) {
                gde_dx_log("Secure doc table create/update successful");
            } else {
                gde_dx_log("Secure doc table create/update failed");
                $fails++;
            }
        }
    } else {
        gde_dx_log("Tables OK, nothing to do");
    }
    if ($fails > 0) {
        delete_site_option('gde_db_version');
        return false;
    } else {
        update_site_option('gde_db_version', $gde_db_ver);
        return true;
    }
}
Example #5
0
                    gde_show_msg(__('Unable to enable diagnostic logging.', 'google-document-embedder'), true);
                    $gdeoptions[$k] = "no";
                }
            }
        } elseif (array_key_exists($k, $gdeoptions)) {
            // all fields where name == settings key
            $gdeoptions[$k] = stripslashes($v);
        }
    }
    if (update_option('gde_options', $gdeoptions)) {
        // update successful
        gde_show_msg(__('Settings <strong>updated</strong>.', 'google-document-embedder'));
    } else {
        gde_show_msg(__('Settings <strong>updated</strong>.', 'google-document-embedder'));
        // not true, but avoids confusion in case where no changes were made
        gde_dx_log('Settings update failed - maybe no changes');
    }
} elseif (isset($_POST['_advanced_import'])) {
    $valid = false;
    // check import file validity
    if (isset($_FILES['import']) && !empty($_FILES['import'])) {
        if ($_FILES['import']['size'] > 0 && is_uploaded_file($_FILES['import']['tmp_name']) && preg_match('/json$/i', $_FILES['import']['name'])) {
            // file OK, check for json content
            $json = json_decode(file_get_contents($_FILES['import']['tmp_name']), true);
            if ($json !== null && is_array($json)) {
                // check for supported content
                if (isset($json['profiles']) || isset($json['settings']) || isset($json[0]['profile_id']) || isset($json['ed_disable'])) {
                    $valid = true;
                }
            }
        }
Example #6
0
/**
 * Activate the plugin
 *
 * @since   0.2
 * @return  void
 * @note	This function must remain in this file
 */
function gde_activate($network_wide)
{
    // check for sufficient php version (minimum supports json_encode)
    if (!(phpversion() >= '5.2.0')) {
        wp_die('Your server is running PHP version ' . phpversion() . ' but this plugin requires at least 5.2.0');
    }
    // set db schema version for this release - global not available here
    $gde_db_ver = "1.2";
    // check for network-wide activation (currently not supported)
    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';
    // create/update profile db, if necessary
    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'));
    }
}