Esempio n. 1
0
/**
 * Execute changes made in WordPress 1.5.
 *
 * @since 1.5.0
 */
function upgrade_130()
{
    global $wpdb;
    // Remove extraneous backslashes.
    $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM {$wpdb->posts}");
    if ($posts) {
        foreach ($posts as $post) {
            $post_content = addslashes(deslash($post->post_content));
            $post_title = addslashes(deslash($post->post_title));
            $post_excerpt = addslashes(deslash($post->post_excerpt));
            if (empty($post->guid)) {
                $guid = get_permalink($post->ID);
            } else {
                $guid = $post->guid;
            }
            $wpdb->update($wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID));
        }
    }
    // Remove extraneous backslashes.
    $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM {$wpdb->comments}");
    if ($comments) {
        foreach ($comments as $comment) {
            $comment_content = deslash($comment->comment_content);
            $comment_author = deslash($comment->comment_author);
            $wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID));
        }
    }
    // Remove extraneous backslashes.
    $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM {$wpdb->links}");
    if ($links) {
        foreach ($links as $link) {
            $link_name = deslash($link->link_name);
            $link_description = deslash($link->link_description);
            $wpdb->update($wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id));
        }
    }
    $active_plugins = __get_option('active_plugins');
    // If plugins are not stored in an array, they're stored in the old
    // newline separated format.  Convert to new format.
    if (!is_array($active_plugins)) {
        $active_plugins = explode("\n", trim($active_plugins));
        update_option('active_plugins', $active_plugins);
    }
    // Obsolete tables
    $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
    $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
    $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
    $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');
    // Update comments table to use comment_type
    $wpdb->query("UPDATE {$wpdb->comments} SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
    $wpdb->query("UPDATE {$wpdb->comments} SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
    // Some versions have multiple duplicate option_name rows with the same values
    $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `{$wpdb->options}` GROUP BY option_name");
    foreach ($options as $option) {
        if (1 != $option->dupes) {
            // Could this be done in the query?
            $limit = $option->dupes - 1;
            $dupe_ids = $wpdb->get_col($wpdb->prepare("SELECT option_id FROM {$wpdb->options} WHERE option_name = %s LIMIT %d", $option->option_name, $limit));
            if ($dupe_ids) {
                $dupe_ids = join($dupe_ids, ',');
                $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_id IN ({$dupe_ids})");
            }
        }
    }
    make_site_theme();
}
    $db = new Database("txtdbapi-examples");
    $db->executeQuery("DELETE FROM addressbook WHERE id = '" . $_GET['id'] . "'");
}
// Check if 'Edit' Button was pressed. If yes, load variables from DB for showing the
// data in the input fields of the form
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
    $db = new Database("txtdbapi-examples");
    $result = $db->executeQuery("SELECT * FROM addressbook WHERE id = '" . $_GET['id'] . "'");
    $result->next();
    $data = $result->getCurrentValuesAsHash();
    $surname = deslash($data['surname']);
    $familyname = deslash($data['familyname']);
    $street = deslash($data['street']);
    $plz = deslash($data['plz']);
    $city = deslash($data['city']);
    $phone = deslash($data['phone']);
    $id = $data['id'];
    $buttonTitle = lang("save-address");
}
// Check if 'Save Address' button was pressed. If yes, update the address in the DB
if (isset($_POST['submitted']) && $_POST['submitted'] == lang('save-address')) {
    $surname = reslash(isset($_POST['surname']) ? $_POST['surname'] : '');
    $familyname = reslash(isset($_POST['familyname']) ? $_POST['familyname'] : '');
    $street = reslash(isset($_POST['street']) ? $_POST['street'] : '');
    $plz = reslash(isset($_POST['plz']) ? $_POST['plz'] : '');
    $city = reslash(isset($_POST['city']) ? $_POST['city'] : '');
    $phone = reslash(isset($_POST['phone']) ? $_POST['phone'] : '');
    $db = new Database("txtdbapi-examples");
    $db->executeQuery("UPDATE addressbook SET surname='{$surname}', familyname='{$familyname}', street='{$street}', plz='{$plz}', city='{$city}', phone='{$phone}' WHERE id = " . $_POST['id']);
    // reset all variables, so it will not be shown in the form again
    $surname = $familyname = $street = $plz = $city = $phone = $id = '';
function upgrade_130() {
	global $wpdb;

	// Remove extraneous backslashes.
	$posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
	if ($posts) {
		foreach($posts as $post) {
			$post_content = addslashes(deslash($post->post_content));
			$post_title = addslashes(deslash($post->post_title));
			$post_excerpt = addslashes(deslash($post->post_excerpt));
			if ( empty($post->guid) )
				$guid = get_permalink($post->ID);
			else
				$guid = $post->guid;

			$wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'");
		}
	}

	// Remove extraneous backslashes.
	$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
	if ($comments) {
		foreach($comments as $comment) {
			$comment_content = addslashes(deslash($comment->comment_content));
			$comment_author = addslashes(deslash($comment->comment_author));
			$wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
		}
	}

	// Remove extraneous backslashes.
	$links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
	if ($links) {
		foreach($links as $link) {
			$link_name = addslashes(deslash($link->link_name));
			$link_description = addslashes(deslash($link->link_description));
			$wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
		}
	}

	// The "paged" option for what_to_show is no more.
	if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
		$wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
	}

	$active_plugins = __get_option('active_plugins');

	// If plugins are not stored in an array, they're stored in the old
	// newline separated format.  Convert to new format.
	if ( !is_array( $active_plugins ) ) {
		$active_plugins = explode("\n", trim($active_plugins));
		update_option('active_plugins', $active_plugins);
	}

	// Obsolete tables
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');

	// Update comments table to use comment_type
	$wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
	$wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");

	// Some versions have multiple duplicate option_name rows with the same values
	$options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
	foreach ( $options as $option ) {
		if ( 1 != $option->dupes ) { // Could this be done in the query?
			$limit = $option->dupes - 1;
			$dupe_ids = $wpdb->get_col("SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit");
			$dupe_ids = join($dupe_ids, ',');
			$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
		}
	}

	make_site_theme();
}
Esempio n. 4
0
function stardict_input()
{
    echo "\nPhase " . $GLOBALS['phase']++ . " : Input\n";
    $bom = chr(239) . chr(187) . chr(191);
    echo "\nInput type [txt/xml/dict]: ";
    $ans = rtrim(fgets(STDIN));
    if ($ans == 'txt') {
        echo "\nFilename: ";
        $fn = rtrim(fgets(STDIN));
        while (!file_exists($fn)) {
            echo "\nFile not found!";
            echo "\nFilename: ";
            $fn = rtrim(fgets(STDIN));
        }
        echo "\nAre you sure input file use UTF-8 charset?[yN]";
        $ans = rtrim(fgets(STDIN));
        if ($ans != 'y') {
            die("\nAbort!\n");
        }
        $s = file_get_contents($fn);
        if (substr($s, 0, 3) == $bom) {
            $ans = '';
            echo "\nRemove UTF-8 BOM?[Yn]";
            $ans = rtrim(fgets(STDIN));
            if ($ans != 'n') {
                $s = substr($s, 3);
            }
        }
        $s = trim($s);
        $s = str_replace("\r\n", "\n", $s);
        $s = explode("\n", $s);
        for ($i = 0; $i < count($s); $i++) {
            $pos = strpos($s[$i], "\t");
            if ($pos == FALSE) {
                die("\nNo definition!\nAbort!\n");
            }
            $z[0][$i] = substr($s[$i], 0, $pos);
            $z[1][$i] = substr($s[$i], $pos + 1);
        }
        for ($i = 0; $i < count($s); $i++) {
            $z[1][$i] = deslash($z[1][$i]);
        }
        $GLOBALS['dict'] = $z;
    } elseif ($ans == 'xml') {
        $wt = $GLOBALS['wt'];
        $et = $GLOBALS['et'];
        echo "\nFilename: ";
        $fn = rtrim(fgets(STDIN));
        while (!file_exists($fn)) {
            echo "\nFile not found!";
            echo "\nFilename: ";
            $fn = rtrim(fgets(STDIN));
        }
        echo "\nAre you sure input file use UTF-8 charset?[yN]";
        $ans = rtrim(fgets(STDIN));
        if ($ans != 'y') {
            die("\nAbort!\n");
        }
        $s = file_get_contents($fn);
        preg_match_all('/<' . $wt . '>.*?<\\/' . $wt . '>/s', $s, $a);
        preg_match_all('/<' . $et . '>.*?<\\/' . $et . '>/s', $s, $b);
        if (count($a[0]) != count($b[0])) {
            die("\nWord number != Explain number\nAbort!\n");
        }
        if (count($a[0]) == 0) {
            die("\nNo Data Found!\nAbort!\n");
        }
        for ($i = 0; $i < count($a[0]); $i++) {
            $a[0][$i] = str_replace('<' . $wt . '>', '', $a[0][$i]);
            $a[0][$i] = str_replace('</' . $wt . '>', '', $a[0][$i]);
            $a[0][$i] = trim($a[0][$i]);
            $b[0][$i] = str_replace('<' . $et . '>', '', $b[0][$i]);
            $b[0][$i] = str_replace('</' . $et . '>', '', $b[0][$i]);
            $b[0][$i] = trim($b[0][$i]);
        }
        $GLOBALS['dict'] = array($a[0], $b[0]);
    } elseif ($ans == 'dict') {
        echo "\nFilename (Suffix is not needed): ";
        $fn = rtrim(fgets(STDIN));
        while (!file_exists($fn)) {
            echo "\nFile not found!";
            echo "\nFilename (Suffix is not needed): ";
            $fn = rtrim(fgets(STDIN));
        }
        ####
    } else {
        die("\nUnknown input mode\n");
    }
}