GGshow reloaded GGshow reloaded

March 9, 2015

How to block a specific network port in Linux?

Question:

How to block a specific network port in Linux?

Answer:

Use iptables commands.
E.g. to block port 21 & 22:

iptables -A OUTPUT -p tcp --dport 21 -j REJECT
iptables -A OUTPUT -p tcp --dport 22 -j REJECT

To block a port permanently

  1. save iptables to a file,
    iptables-save > /etc/sysconfig/iptables
  2. add this line to /etc/rc.local
    iptables-restore < /etc/sysconfig/iptables
Filed under: Linux,Web Servers — Tags: , , — GG @ 5:27 pm

September 18, 2014

How to perform factory reset on MacBook Pro?

Question:

How to perform factory reset on MacBook Pro?

Answer:

  1. Hold down Cmd+R keys during startup to enter OSX Recovery
  2. Select Disk Utility, select Macintosh HD, click Erase.
  3. Once done, Quit Disk Utility, and select Reinstall OS X.

Reference

OS X: About OS X Recovery

Filed under: MacOS — Tags: , , , , — GG @ 5:22 pm

January 4, 2014

Chord Canvas

This is a HTML5 build of Dynamic Chord Diagam.

Usage:

  • Include JavaScript at HTML head.
    <script src="http://commondatastorage.googleapis.com/ggshow/files/chordcanvas/chordcanvas-1-0-0.min.js"></script>
  • Creating/rendering chord instance.
    var myChord = new ChordCanvas(value, size);
    myChord.render();

Simplified method:

  • <script>new ChordCanvas("C,X,3,2,0,1,0","100").render();</script>

Customize Color:

  • var chord1 = new ChordCanvas("C,X,3,2,0,1,0","150");
    chord1.backgroundcolor = "#CCF";
    chord1.bordercolor = "";
    chord1.titlecolor = "#FFF";
    chord1.labelcolor = "#00F";
    chord1.chordcolor = "#00F";
    chord1.titlebackgroundcolor = "#00F";
    chord1.render();

Overwrite chord container display style:

  • Chord container has block display by default, you can overwrite the display style by .chord-container class selector. e.g:
    <style>
    .chord-container {
        display:inline-block;
    }
    </style>

Examples:

Source:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Chord Canvas - Example 01</title>
<style>
.chord-container {
display:inline-block;
}
</style>
<script src="http://commondatastorage.googleapis.com/ggshow/files/chordcanvas/chordcanvas-1-0-0.min.js"></script>
</head>
<body>
<h1>Chord Canvas Examples</h1>
<h3>Basic</h3>
<script>new ChordCanvas("C,X,3,2,0,1,0","100").render();</script>
<script>new ChordCanvas("Am,X,0,2,2,1,0","100").render();</script>
<script>new ChordCanvas("F,X,X,3,2,1,1","100").render();</script>
<script>new ChordCanvas("G,X,0,2,2,1,0","100").render();</script>
<br />
<script>new ChordCanvas("C#7-5,X,X,3,4,2,3","100").render();</script>
<script>new ChordCanvas("D♭7-9,X,4,3,4,3,X","100").render();</script>
<script>new ChordCanvas("E♭,11,10,8,8,8,11","100").render();</script>
<script>new ChordCanvas("B♭m,X,X,11,10,11,9","100").render();</script>
<h3>Customize Size</h3>
<script>new ChordCanvas("C,X,3,2,0,1,0","150").render();</script>
<script>new ChordCanvas("C,X,3,2,0,1,0","250").render();</script>
<script>new ChordCanvas("C,X,3,2,0,1,0","").render();</script>
<h3>Customize Color</h3>
<script>
var chord1 = new ChordCanvas("C,X,3,2,0,1,0","150");
chord1.backgroundcolor = "#CCF";
chord1.bordercolor = "";
chord1.titlecolor = "#FFF";
chord1.labelcolor = "#00F";
chord1.chordcolor = "#00F";
chord1.titlebackgroundcolor = "#00F";
chord1.render();

var chord2 = new ChordCanvas("C,8,10,10,9,8,8","150");
chord2.backgroundcolor = "#F00";
chord2.bordercolor = "#F00";
chord2.titlecolor = "#F00";
chord2.labelcolor = "#000";
chord2.chordcolor = "#FFF";
chord2.titlebackgroundcolor = "#FFF";
chord2.render();
</script>
</body>
</html>
Filed under: CSS,HTML5,JavaScript — Tags: , , , , , , — GG @ 8:44 am

b2evolution to WordPress migration

I’ve been looking for b2evolution to WordPress importer for long time. What I can find on the web are only migration script for older version of b2evo/wp, hence I’ve decided to write one on my own, for importing data from b2evolution 4.0.5 to WordPress 3.7.1. I’ve tested the script with WordPress 3.8.0 too. I’m hereby sharing it to whoever needs it.

Instruction

  1. Place this file at the same directory with your wp-config.php
  2. Access the URL at web browser, e.g.: http://localhost/b2wp.php
  3. Fill up the form with database connection detail, and submit.
  4. Select import options, and start import.

Warning

  1. Backup all your databases safely before proceed.
  2. Try it with a fresh installation of WordPress instead of production site.
  3. Use this script at your own risk 🙂

Download

  • b2wp.php – Tested with b2evo 4.0.5 to wp 3.7.1/3.8.0
  • b2wp_kp.zip – provided by KP for b2evo 5.1.2 to wp 4.
<?php
/*
* b2wp.php
* Title        : B2evolution to WordPress Importer
* Version      : 1.0.2
* Author URL   : http://www.ggshow.com
* Description  : Import Authors, Categories, Posts, Tags, and Comments, from
*               B2evolution database to WordPress database.
*/

function slug($str) {
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $str)));
}

$output = '';
$step = 1;
require_once( dirname(__FILE__) . '/wp-config.php' );
$target['db_host'] = DB_HOST;
$target['db_user'] = DB_USER;
$target['db_password'] = DB_PASSWORD;
$target['db_name'] = DB_NAME;
$wp_con = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$target['status'] = (mysqli_connect_errno()) ? 'Error' : 'Connected';
$output .= ($target['status'] == 'Error') ? 'Error connecting WordPress database!<br />' : '';
$source['db_host'] = ($_POST['source_dbhost'] == '') ? 'localhost' : htmlentities($_POST['source_dbhost']);
$source['db_user'] = htmlentities($_POST['source_dbuser']);
$source['db_password'] = htmlentities($_POST['source_dbpassword']);
$source['db_name'] = htmlentities($_POST['source_dbname']);
if (!empty($_POST['source_dbname'])) {
$b2_con = new mysqli($source['db_host'], $source['db_user'], $source['db_password'], $source['db_name']);
$source['status'] = (mysqli_connect_errno()) ? 'Error' : 'Connected';
$output .= ($source['status'] == 'Error') ? 'Error connecting B2evolution database!<br />' : '';
} else {
$source['status'] = '';
$output .= 'Please fill up B2evolution database connection detail!<br />';
}
$target['table_prefix'] = (!empty($_POST['target_table_prefix'])) ? $wp_con->real_escape_string($_POST['target_table_prefix']) : 'wp_';
$source['table_prefix'] = (!empty($_POST['source_table_prefix'])) ? $wp_con->real_escape_string($_POST['source_table_prefix']) : 'evo_';
if ($source['status'] == 'Connected') {
$sql = " SHOW TABLES LIKE \"" . $source['table_prefix'] . "%\"";
$res = $b2_con->query($sql);
if ($res->num_rows <= 0) {
$source['status'] = 'Error';
$output .= "Invalid B2evo table prefix.<br />";
} else {
$sql = "SELECT DISTINCT `" . $source['table_prefix'] . "blogs`.* FROM `" . $source['table_prefix'] . "blogs`";
$res = $b2_con->query($sql);
$b2_blog_selected = ($_POST['b2_blog'] == '') ? 1 : $_POST['b2_blog'];
$b2_blog_select = '<select name="b2_blog">';
while ($row = $res->fetch_array()) {
$b2_blog_selected_str = '';
if ($row['blog_ID'] == $b2_blog_selected) {
$b2_blog_selected_str = 'selected';
$b2_blog_selected_row = $row;
}
$b2_blog_select .= '<option value="' . $row['blog_ID'] . '" ' . ($b2_blog_selected_str) . ' >' . $row['blog_name'] . '</option>';
}
$b2_blog_select .= '</select>';
}
}
if ($target['status'] == 'Connected') {
$sql = " SHOW TABLES LIKE \"" . $target['table_prefix'] . "%\"";
$res = $wp_con->query($sql);
if ($res->num_rows <= 0) {
$target['status'] = 'Error';
$output .= "Invalid WordPress table prefix.<br />";
} else {
$sql = "SELECT DISTINCT `" . $target['table_prefix'] . "users`.* FROM `" . $target['table_prefix'] . "users`";
$res = $wp_con->query($sql);
$b2_user_selected = ($_POST['b2_user'] == '') ? 0 : $_POST['b2_user'];
$b2_user_select = '<select name="b2_user">';
$b2_user_select .= '<option value="0">Import B2evo users</option>';
while ($row = $res->fetch_array()) {
if ($row['ID'] == $b2_user_selected) {
$b2_user_selected_str = 'selected';
$b2_user_selected_row = $row;
} else {
$b2_user_selected_str = '';
}
$b2_user_select .= '<option value="' . $row['ID'] . '" ' . ($b2_user_selected_str) . ' >Assign posts to ' . $row['user_login'] . '</option>';
}
$b2_user_select .= '</select>';
}
}
if ($source['status'] == 'Connected' && $target['status'] == 'Connected') {
$step = 2;
}
if ($step >= 2) {
$b2_cat_selected = ($_POST['b2_cat'] == '') ? 0 : $_POST['b2_cat'];
$b2_cat_select = '<select name="b2_cat">';
$b2_cat_select .= '<option value="1" ' . ($b2_cat_selected == 1 ? 'selected' : '') . '>a: Uncategorized</option>';
$b2_cat_select .= '<option value="2" ' . ($b2_cat_selected == 2 ? 'selected' : '') . '>b: Create a new category</option>';
$b2_cat_select .= '<option value="3" ' . ($b2_cat_selected == 3 ? 'selected' : '') . '>c: Import B2evo categories</option>';
$b2_cat_select .= '<option value="4" ' . ($b2_cat_selected == 4 ? 'selected' : '') . '>b+c</option>';
$b2_cat_select .= '</select>';
$b2_checbox_tags = '<input type="checkbox" value="1" name="b2_tags" ' . (($_POST['b2_tags'] == 1) ? 'checked' : '') . ' />';
$b2_checbox_comments = '<input type="checkbox" value="1" name="b2_comments" ' . (($_POST['b2_comments'] == 1) ? 'checked' : '') . ' />';
if ($_POST['step'] == '3' && $target['status'] != 'Error' && $source['status'] != 'Error') {
$step = 3;
}
}
if ($step >= 3) {
if ($b2_cat_selected == 1) {
$root_id = 1;
$taxonomy[1] = 1;
} else if ($b2_cat_selected == 2 || $b2_cat_selected == 4) {
unset($data);
$row = $b2_blog_selected_row;
$data['blog_name'] = $wp_con->real_escape_string($row['blog_name']);
$data['blog_urlname'] = slug($wp_con->real_escape_string($row['blog_urlname']));
$data['blog_description'] = empty($row['blog_description'])?$wp_con->real_escape_string($row['blog_tagline']):$wp_con->real_escape_string($row['blog_description']);
$sql = " INSERT INTO `" . $target['table_prefix'] . "terms` (`name`,`slug`,`term_group`) VALUES ('" . $data['blog_name'] . "','" . $data['blog_urlname'] . "','0');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$root_id = $wp_con->insert_id;
$newcat[0] = $root_id;
$sql = " INSERT INTO `" . $target['table_prefix'] . "term_taxonomy` (`term_id`,`taxonomy`,`description`,`parent`,`count`) VALUES ('" . $newcat[0] . "','category','" . $data['blog_description'] . "',0,0);";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$id = $wp_con->insert_id;
$taxonomy[$newcat[0]] = $id;
$output .= "1 new category created!<br />";
} else {
$root_id = 0;
$taxonomy[0] = 1;
}
if ($b2_cat_selected == 3 || $b2_cat_selected == 4) {
$sql = "SELECT DISTINCT `" . $source['table_prefix'] . "categories`.* FROM `" . $source['table_prefix'] . "categories` WHERE `cat_blog_ID` = " . $wp_con->real_escape_string($b2_blog_selected);
$res = $b2_con->query($sql);
$count = 0;
while ($row = $res->fetch_array()) {
$sql = " INSERT INTO `" . $target['table_prefix'] . "terms` (`name`,`slug`,`term_group`) VALUES ('" . $wp_con->real_escape_string($row['cat_name']) . "','" . $wp_con->real_escape_string($row['cat_urlname']) . "','0');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$id = $wp_con->insert_id;
$newcat[$row['cat_ID']] = $id;
$count++;
}
$sql = "SELECT DISTINCT `" . $source['table_prefix'] . "categories`.* FROM `" . $source['table_prefix'] . "categories` WHERE `cat_blog_ID` = " . $wp_con->real_escape_string($b2_blog_selected);
$res = $b2_con->query($sql);
while ($row = $res->fetch_array()) {
$data['parent_id'] = (isset($newcat[$row['cat_parent_ID']]) ? $newcat[$row['cat_parent_ID']] : $root_id);
$data['description'] = $wp_con->real_escape_string($row['cat_description']);
$sql = " INSERT INTO `" . $target['table_prefix'] . "term_taxonomy` (`term_id`,`taxonomy`,`description`,`parent`,`count`) VALUES ('" . $newcat[$row['cat_ID']] . "','category','" . $data['description'] . "','" . $data['parent_id'] . "',0);";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$id = $wp_con->insert_id;
$taxonomy[$newcat[$row['cat_ID']]] = $id;
}
$output .= $count . " categories imported!<br />";
}
if ($b2_cat_selected != 1) {
$sql = "UPDATE `" . $target['table_prefix'] . "options` SET `option_value`='' WHERE `option_name`='category_children';";
$wp_con->query(trim(str_replace("\n", "", $sql)));
}
if ($wp_user_selected == 0) {
$sql = " SELECT DISTINCT `" . $source['table_prefix'] . "users`.* FROM `" . $source['table_prefix'] . "users` INNER JOIN `" . $source['table_prefix'] . "blogusers` ON `" . $source['table_prefix'] . "users`.`user_ID` = `" . $source['table_prefix'] . "blogusers`.`bloguser_user_ID` WHERE `" . $source['table_prefix'] . "blogusers`.`bloguser_blog_ID` = " . $b2_con->real_escape_string($b2_blog_selected) . " AND `user_login`<>'admin'";
$res = $b2_con->query($sql);
$count = 0;
while ($row = $res->fetch_array()) {
$sql = " SELECT * FROM `" . $target['table_prefix'] . "users` WHERE `user_login` = '" . $wp_con->real_escape_string($row['user_login']) . "';";
$pres = $wp_con->query(trim(str_replace("\n", "", $sql)));
if ($prow = $pres->fetch_array()) {
$id = $prow['ID'];
} else {
$sql = " INSERT INTO `" . $target['table_prefix'] . "users` (`user_login`,`user_pass`,`user_nicename`,`user_email`,`user_url`,`user_registered`,`user_status`,`display_name`) VALUES ('" . $wp_con->real_escape_string($row['user_login']) . "','" . $wp_con->real_escape_string($row['user_pass']) . "','" . $wp_con->real_escape_string($row['user_login']) . "','" . $wp_con->real_escape_string($row['user_email']) . "','" . $wp_con->real_escape_string($row['user_url']) . "','" . $wp_con->real_escape_string($row['dateYMDhour']) . "','0','" . $wp_con->real_escape_string($row['user_login']) . "');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$id = $wp_con->insert_id;
$sql = " INSERT INTO `" . $target['table_prefix'] . "usermeta` (`user_id`,`meta_key`,`meta_value`) VALUES ('" . $id . "', 'first_name', '" . $wp_con->real_escape_string($row['user_firstname']) . "');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$sql = " INSERT INTO `" . $target['table_prefix'] . "usermeta` (`user_id`,`meta_key`,`meta_value`) VALUES ('" . $id . "', 'last_name', '" . $wp_con->real_escape_string($row['user_lastname']) . "');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$sql = " INSERT INTO `" . $target['table_prefix'] . "usermeta` (`user_id`,`meta_key`,`meta_value`) VALUES ('" . $id . "', 'nickname', '" . $wp_con->real_escape_string($row['user_nickname']) . "');";
$wp_con->query(trim(str_replace("\n", "", $sql)));
$count++;
}
$newuser[$row['user_ID']] = $id;
}
if ($count > 0) {
$output .= $count . " users imported!<br />";
}
} else {
$newuser[0] = $wp_user_selected;
}
$sql = "SELECT DISTINCT `" . $source['table_prefix'] . "items__item`.* FROM `" . $source['table_prefix'] . "items__item` INNER JOIN `" . $source['table_prefix'] . "categories` ON `" . $source['table_prefix'] . "items__item`.`post_main_cat_ID` = `" . $source['table_prefix'] . "categories`.`cat_ID` WHERE `" . $source['table_prefix'] . "categories`.`cat_blog_ID` = " . $b2_blog_selected;
$res = $b2_con->query($sql);
$pcount = 0;
$tcount = 0;
$ccount = 0;
while ($row = $res->fetch_array()) {
unset($data);
if ($b2_user_selected == 0) {
$data['user'] = isset($newuser[$row['post_creator_user_ID']]) ? $newuser[$row['post_creator_user_ID']] : 1;
} else {
$data['user'] = $b2_user_selected;
}
$data['category'] = isset($newcat[$row['post_main_cat_ID']]) ? $newcat[$row['post_main_cat_ID']] : $root_id;
switch ($row['post_status']) {
case 'published':
case 'deprecated':
$data['status'] = 'publish';
break;
case 'protected':
case 'private':
$data['status'] = 'private';
break;
case 'redirected':
$row['post_content'] = "<a href='".htmlentities($row['post_url'])."'>".htmlentities($row['post_url'])."</a>";
default:
$data['status'] = 'draft';
}
$data['date'] = $row['post_datecreated'];
$data['date_gmt'] = gmdate("Y-m-d G:i:s ", strtotime($data['date']));
$data['modified'] = $row['post_datemodified'];
$data['modified_gmt'] = gmdate("Y-m-d G:i:s ", strtotime($data['modified']));
$psql = "SELECT COUNT(1) AS comment_count FROM `" . $source['table_prefix'] . "comments` WHERE `" . $source['table_prefix'] . "comments`.`comment_post_ID` = " . $row['post_ID'];
$pres = $b2_con->query($psql);
$prow = $pres->fetch_array();
$data['comment_count'] = $prow['comment_count'];
$data['post_content'] = $row['post_content'];
$data['post_excerpt'] = $row['post_excerpt'];
$data['title'] = $row['post_title'];
$psql = "INSERT INTO `" . $target['table_prefix'] . "posts` (`post_author`,`post_content`,`post_title`,`post_excerpt`,`post_status`,`post_date`,`post_date_gmt`,`post_modified`,`post_modified_gmt`,`comment_count`, `to_ping`, `pinged`, `post_content_filtered`) VALUES ('" . $data['user'] . "','" . $wp_con->real_escape_string($data['post_content']) . "','" . $wp_con->real_escape_string($data['title']) . "','" . $wp_con->real_escape_string($data['post_excerpt']) . "','" . $data['status'] . "','" . $data['date'] . "','" . $data['date_gmt'] . "','" . $data['modified'] . "','" . $data['modified_gmt'] . "','" . $data['comment_count'] . "', '', '', '');";
$wp_con->query(trim(str_replace("\n", "", $psql)));
$id = $wp_con->insert_id;
$eid = $row['post_ID'];
$psql = "INSERT INTO `wp_term_relationships` (`object_id`,`term_taxonomy_id`,`term_order`) VALUES (" . $id . "," . $taxonomy[$data['category']] . ",0);";
$wp_con->query(trim(str_replace("\n", "", $psql)));
$psql = "SELECT * FROM `" . $source['table_prefix'] . "postcats` WHERE `postcat_post_ID` = " . $row['post_ID'];
$pres = $b2_con->query($psql);
while ($prow = $pres->fetch_array()) {
$psql = "INSERT INTO `wp_term_relationships` (`object_id`,`term_taxonomy_id`,`term_order`) VALUES (" . $id . "," . $taxonomy[$newcat[$prow['postcat_cat_ID']]] . ",0);";
$wp_con->query(trim(str_replace("\n", "", $psql)));
}
$pcount++;
if ($_POST['b2_tags'] == 1) {
$psql = "SELECT `itag_itm_ID`, LOWER(cast(`" . $source['table_prefix'] . "items__tag`.`tag_name` as char)) AS tag_name FROM `" . $source['table_prefix'] . "items__tag` INNER JOIN `" . $source['table_prefix'] . "items__itemtag` ON `itag_tag_ID` = `tag_ID` WHERE `itag_itm_ID` = " . $row['post_ID'];
$pres = $b2_con->query($psql);
while ($prow = $pres->fetch_array()) {
unset($data);
$data['tag_name'] = $wp_con->real_escape_string($prow['tag_name']);
$data['tag_slug'] = slug($data['tag_name']);
$tsql = "SELECT * FROM `" . $target['table_prefix'] . "terms` WHERE `slug` = '" . $data['tag_slug'] . "';";
$tres = $wp_con->query(trim(str_replace("\n", "", $tsql)));
if ($trow = $tres->fetch_array()) {
$tid = $trow['term_id'];
} else {
$tsql = "INSERT INTO `" . $target['table_prefix'] . "terms` (`name`,`slug`,`term_group`) VALUES ('" . $data['tag_name'] . "','" . $data['tag_slug'] . "',0);";
$wp_con->query(trim(str_replace("\n", "", $tsql)));
$tid = $wp_con->insert_id;
$tcount++;
}
$tsql = "SELECT * FROM `" . $target['table_prefix'] . "term_taxonomy` WHERE `term_id` = '" . $tid . "' AND `taxonomy`='post_tag';";
$tres = $wp_con->query(trim(str_replace("\n", "", $tsql)));
if ($trow = $tres->fetch_array()) {
$ttid = $trow['term_taxonomy_id'];
} else {
$tsql = "INSERT INTO `" . $target['table_prefix'] . "term_taxonomy` (`term_id`,`taxonomy`,`description`,`parent`,`count`) VALUES (" . $tid . ",'post_tag','',0,0);";
$wp_con->query(trim(str_replace("\n", "", $tsql)));
$ttid = $wp_con->insert_id;
}
$tsql = "SELECT * FROM `" . $target['table_prefix'] . "term_relationships` WHERE `object_id` = '" . $id . "' AND `term_taxonomy_id`='" . $ttid . "';";
$tres = $wp_con->query(trim(str_replace("\n", "", $tsql)));
if ($trow = $tres->fetch_array()) {

} else {
$tsql = "INSERT INTO `" . $target['table_prefix'] . "term_relationships` (`object_id`,`term_taxonomy_id`,`term_order`) VALUES (" . $id . "," . $ttid . ",0);";
$wp_con->query(trim(str_replace("\n", "", $tsql)));
}
}
}
if ($_POST['b2_comments'] == 1) {
$psql = "SELECT `" . $source['table_prefix'] . "comments`.* , `" . $source['table_prefix'] . "users`.`user_nickname`, `" . $source['table_prefix'] . "users`.`user_url`, `" . $source['table_prefix'] . "users`.`user_email` FROM `" . $source['table_prefix'] . "comments` LEFT JOIN `" . $source['table_prefix'] . "users` ON `" . $source['table_prefix'] . "comments`.`comment_author_ID` = `" . $source['table_prefix'] . "users`.`user_ID` WHERE `" . $source['table_prefix'] . "comments`.`comment_post_ID`=" . $eid;
$pres = $b2_con->query($psql);
while ($prow = $pres->fetch_array()) {
unset($data);
if ($prow['comment_author_ID'] != NULL) {
$data['author'] = $wp_con->real_escape_string($prow['user_nickname']);
$data['url'] = $wp_con->real_escape_string($prow['user_url']);
$data['email'] = $wp_con->real_escape_string($prow['user_email']);
} else {
$data['author'] = $wp_con->real_escape_string($prow['comment_author']);
$data['url'] = $wp_con->real_escape_string($prow['comment_author_url']);
$data['email'] = $wp_con->real_escape_string($prow['comment_author_email']);
}
$data['time'] = $wp_con->real_escape_string($prow['comment_date']);
$data['gm_time'] = gmdate("Y-m-d G:i:s ", strtotime($data['time']));
$data['comment_type'] = $wp_con->real_escape_string($prow['comment_type']);
switch ($data['comment_type']) {
case 'trackback':
break;
case 'pingback':
case 'linkback':
$data['comment_type'] = 'pingback';
break;
case 'comment':
default:
$data['comment_type'] = '';
break;
}
$data['comment_status'] = $wp_con->real_escape_string($prow['comment_status']);
switch ($data['comment_status']) {
case 'published':
case 'deprecated':
$data['comment_status'] = '1';
break;
case 'protected':
case 'private':
$data['comment_status'] = 'private';
break;
case 'draft':
case 'redirected':
default:
$data['comment_status'] = '0';
}
$data['comment_author_IP'] = $wp_con->real_escape_string($prow['comment_author_IP']);
$data['comment_content'] = $wp_con->real_escape_string($prow['comment_content']);
$data['comment_karma'] = $wp_con->real_escape_string($prow['comment_karma']);
$csql = "INSERT INTO `" . $target['table_prefix'] . "comments` (`comment_post_ID`,`comment_author`,`comment_author_email`,`comment_author_url`,`comment_author_IP`,`comment_date`,`comment_date_gmt`,`comment_content`,`comment_karma`, `comment_approved`, `comment_type`) VALUES ('" . $id . "','" . $data['author'] . "','" . $data['email'] . "','" . $data['url'] . "','" . $data['comment_author_IP'] . "','" . $data['time'] . "','" . $data['gm_time'] . "','" . $data['comment_content'] . "','" . $data['comment_karma'] . "','" . $data['comment_status'] . "','" . $data['comment_type'] . "');";
$wp_con->query(trim(str_replace("\n", "", $csql)));
$ccount++;
}
}
}
$output .= $pcount . " posts imported!<br />";
if ($_POST['b2_tags'] == 1) {
$output .= $tcount . " tags imported!<br />";
}
if ($_POST['b2_comments'] == 1) {
$output .= $ccount . " comments imported!<br />";
}
}
mysqli_free_result($res);
mysqli_free_result($pres);
mysqli_free_result($tres);
mysqli_close($wp_con);
mysqli_close($b2_con);
?>
<!DOCTYPE html>
<html>
<head>
<title>b2wp - b2evolution to wordpress importer</title>
<meta charset="UTF-8">
<style>
body { font: 10pt sans-serif; }
table { width: 480px; border: #ccc 1px solid; margin:10px auto; }
th, td { width: 160px; }
caption { font: bold 16pt sans-serif; }
</style>
</head>

<body>
<form action="" method="post">
<table>
<caption>B2WP</caption>
<tr>
<th></th>
<th>B2evolution</th>
<th>Wordpress</th>
</tr>
<tr>
<td>Host</td>
<td><input name="source_dbhost" type="text" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $source['db_host']; ?>" /></td>
<td><input type="text" disabled value="<?php echo $target['db_host']; ?>" /></td>
</tr>
<tr>
<td>User</td>
<td><input name="source_dbuser" type="text" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $source['db_user']; ?>" /></td>
<td><input type="text" disabled value="<?php echo $target['db_user']; ?>" /></td>
</tr>
<tr>
<td>Password</td>
<td><input name="source_dbpassword" type="password" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $source['db_password']; ?>" /></td>
<td><input type="password" disabled value="<?php echo $target['db_password']; ?>" /></td>
</tr>
<tr>
<td>Database</td>
<td><input name="source_dbname" type="text" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $source['db_name']; ?>" /></td>
<td><input type="text" disabled value="<?php echo $target['db_name']; ?>" /></td>
</tr>
<tr>
<td>Table Prefix</td>
<td><input type="text" name="source_table_prefix" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $source['table_prefix']; ?>" /></td>
<td><input type="text" name="target_table_prefix" <?php if ($step >= 2) echo 'readonly'; ?> value="<?php echo $target['table_prefix']; ?>" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" disabled value="<?php echo $source['status']; ?>" /></td>
<td><input type="text" disabled value="<?php echo $target['status']; ?>" /></td>
</tr>
<?php if ($step == 1) { ?>
<tr>
<td></td>
<td colspan="2"><input type="submit" value="Connect" /></td>
</tr>
<?php } else if ($step >= 2) { ?>
<tr>
<td colspan="3"><input type="hidden" name="step" value="3"/><hr /></td>
</tr>
<tr>
<td>B2evo Blog</td>
<td colspan="2">
<?php echo $b2_blog_select; ?>
</td>
</tr>
<tr>
<td valign="top">Import Options</td>
<td colspan="2">
<input type="checkbox" checked disabled> <label for="b2_posts">Posts</label><br />
<input type="checkbox" checked disabled> <label for="b2_user">Authors</label> <?php echo $b2_user_select; ?><br />
<input type="checkbox" checked disabled> <label for="b2_cat">Categories</label> <?php echo $b2_cat_select; ?><br />
<?php echo $b2_checbox_tags; ?> <label for="b2_tags">Tags</label><br />
<?php echo $b2_checbox_comments; ?> <label for="b2_comments">Comments</label><br />
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<input type="submit" value="Import" />
<input type="button" value="Back" onclick="location.href='b2wp.php';" />
</td>
</tr>
<?php } ?>
<?php if (!empty($output)) { ?>
<tr>
<td colspan="3"><hr /><?php echo $output; ?></td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>

This is NOT a WordPress importer plugin, this is simply a PHP script to extract content (Authors, Categories, Posts, Tags, and Comments) from a b2evolution database and insert into WordPress database. This migration script does NOT catered importing of uploaded media files. Feel free to modify it as per your needs. You might want to try these WordPress plugins Add From Server or Import External Images for migrating your uploaded files.

Special thanks
Thanks to RealNitro’s b2evo2wp.php script, it was my primary source of reference for understanding b2evo/wp database schema.
Thanks to KP for sharing b2evolution 5.1.2 to WorPress 4 migration script.

Filed under: MySQL,PHP,Web — Tags: , , , , — GG @ 6:53 am

November 18, 2013

PHP client denied by server configuration

Issue:

  • AH01630: client denied by server configuration
  • Forbidden
    You don’t have permission to access /___ on this server.
    Apache/2.4.6 (Ubuntu) Server at www.___.com Port ___

Reason:

  • New way to do access control in Apache 2.4 and above.

Solution:

  • Edit Apache configuration , replace Allow from all to Require all granted

More Info:

Filed under: PHP,Web — Tags: , , , — GG @ 3:15 pm

October 19, 2013

PHP none could be negotiated

Issue:
Negotiation: discovered file(s) matching request: /var/www/index (None could be negotiated).

Reason:
PHP mime type has not been enabled.

Solution:
Edit Apache configuration (apache2.conf / httpd.conf / mime.conf), add or uncomment line below:

AddType application/x-httpd-php .php
Filed under: PHP — Tags: , , — GG @ 3:27 pm

August 7, 2013

PHP unexpected end of file

Issue:

  • Parse error: syntax error, unexpected end of file in ___ on line ___

Reason:

  • short_open_tags has been disabled in PHP configuration on the server.
  • Short form of PHP open tag (<? ?>) is not allowed.
  • PHP does not recognize code between short tag <? and ?>

Solution:

  • Avoid using short tag, replace short tag (<? and ?>) with full tag (<?php and ?>), and <?=… ?> with <?php echo …; ?>.

    or

  • For PHP v5.4.0 or newer
    Edit php.ini
    find
    short_open_tag = Off
    change it to:
    short_open_tag = On

    If short_open_tag is enabled, you will not be able to use JSAPI tag (<?js=…?>) or XML tag (<?xml … ?>) inline.
    You will be required to echo/print it with PHP, for example: <?php echo ‘<?xml version=”1.0″?>’; ?>.

More Info:

February 16, 2013

Webpage Editable Switch

FREE! A handy web browser extension/add-on to turn document body contentEditable on or off.

* Pencil icon used in this extension was downloaded from http://openclipart.org

Webpage Editable Switch 1.0 for Firefox

Download WES 1.0 for Firefox

Webpage Editable Switch 1.0 for Chrome

Download WES 1.0 for Chrome

Filed under: Web,Web Browsers — Tags: , , , , , — GG @ 10:50 pm

February 10, 2013

Interesting route of 216.81.59.173

Try run this command in your terminal:

traceroute -m 100 216.81.59.173

Or if you are using Windows:

tracert -h 100  216.81.59.173

It gives output like this:

...
 17     *        *        *     Request timed out.
 18   595 ms   619 ms   608 ms  Episode.IV [206.214.251.1]
 19   566 ms   605 ms   703 ms  A.NEW.HOPE [206.214.251.6]
 20   580 ms   658 ms   629 ms  It.is.a.period.of.civil.war [206.214.251.9]
 21   587 ms   648 ms   658 ms  Rebel.spaceships [206.214.251.14]
 22   564 ms   629 ms   619 ms  striking.from.a.hidden.base [206.214.251.17]
 23   565 ms   658 ms   610 ms  have.won.their.first.victory [206.214.251.22]
 24   611 ms   622 ms   619 ms  against.the.evil.Galactic.Empire [206.214.251.25]
 25   564 ms   600 ms   618 ms  During.the.battle [206.214.251.30]
 26   643 ms   641 ms   624 ms  Rebel.spies.managed [206.214.251.33]
 27   575 ms   638 ms   598 ms  to.steal.secret.plans [206.214.251.38]
 28   614 ms   645 ms   612 ms  to.the.Empires.ultimate.weapon [206.214.251.41]
 29   639 ms   688 ms   702 ms  the.DEATH.STAR [206.214.251.46]
 30   596 ms   639 ms   629 ms  an.armored.space.station [206.214.251.49]
 31   562 ms  1452 ms   378 ms  with.enough.power.to [206.214.251.54]
 32   405 ms   389 ms   409 ms  destroy.an.entire.planet [206.214.251.57]
 33   426 ms   438 ms   438 ms  Pursued.by.the.Empires [206.214.251.62]
 34   442 ms   441 ms   449 ms  sinister.agents [206.214.251.65]
 35   436 ms   559 ms   439 ms  Princess.Leia.races.home [206.214.251.70]
 36   417 ms   448 ms   441 ms  aboard.her.starship [206.214.251.73]
 37   430 ms   438 ms   438 ms  custodian.of.the.stolen.plans [206.214.251.78]
 38   452 ms   450 ms   449 ms  that.can.save.her [206.214.251.81]
 39   463 ms   430 ms   427 ms  people.and.restore [206.214.251.86]
 40   444 ms   469 ms   439 ms  freedom.to.the.galaxy [206.214.251.89]
 41   535 ms   438 ms   449 ms  0-------------------0 [206.214.251.94]
 42   437 ms   498 ms   439 ms  0------------------0 [206.214.251.97]
 43   426 ms   438 ms   449 ms  0-----------------0 [206.214.251.102]
 44   436 ms   439 ms   478 ms  0----------------0 [206.214.251.105]
 45   444 ms   438 ms   449 ms  0---------------0 [206.214.251.110]
 46  2227 ms   387 ms   388 ms  0--------------0 [206.214.251.113]
 47   392 ms   581 ms   399 ms  0-------------0 [206.214.251.118]
 48   406 ms   399 ms   398 ms  0------------0 [206.214.251.121]
 49   416 ms   448 ms   449 ms  0-----------0 [206.214.251.126]
 50   416 ms   438 ms   438 ms  0----------0 [206.214.251.129]
 51   435 ms   438 ms   438 ms  0---------0 [206.214.251.134]
 52   445 ms   458 ms   449 ms  0--------0 [206.214.251.137]
 53   437 ms   438 ms   435 ms  0-------0 [206.214.251.142]
 54   612 ms   448 ms   448 ms  0------0 [206.214.251.145]
 55   443 ms   480 ms   448 ms  0-----0 [206.214.251.150]
 56   455 ms   469 ms   494 ms  0----0 [206.214.251.153]
 57   402 ms   398 ms   398 ms  0---0 [206.214.251.158]
 58   415 ms   399 ms   388 ms  0--0 [206.214.251.161]
 59   428 ms   448 ms   433 ms  0-0 [206.214.251.166]
 60   458 ms   440 ms   439 ms  00 [206.214.251.169]
 61   436 ms   458 ms   459 ms  I [206.214.251.174]
 62   429 ms   449 ms   449 ms  By.Ryan.Werber [206.214.251.177]
 63   437 ms   458 ms   447 ms  When.CCIEs.Get.Bored [206.214.251.182]
 64   475 ms   456 ms   471 ms  read.more.at.beaglenetworks.net [206.214.251.185]
 65   437 ms   438 ms   438 ms  FIN [216.81.59.173]

Trace complete.
Filed under: Linux,Windows — Tags: , , , , , , — GG @ 6:37 pm

January 2, 2013

60 minutes spontaneous reboot

Issue:
PC reboot itself automatically every hour (60 minutes).

Software?
The option to automatically restart on system failure has been turned off.
There is no scheduled task or cron job running hourly, no any sign indicates a virus or malware infection.
It happens even in newly installed OS, regardless of what operating system is running, Windows (XP/Vista/7/8/10) or Linux (Ubuntu/Debian/CentOS/RedHat/Fedora/SuSE).

Hardware?
Motherboard, CPU, RAM, hard drive, power supply, cables, fans, keyboard, mouse, screws… Everything seems to work properly except it just black off every time when it is the plot twist of your favorite TV series, how cruel…
No faulty hardware, no overheating, no power failure. No, the reset button is fine, don’t bother it.

Solution:
Some say it was a bad capacitor on motherboard causing the issue, some say it was the battery. I get rid of my PC hourly restart problem by simply update the system BIOS. If you are about to despair, try it 🙂

Filed under: Hardwares — Tags: , , , , , — GG @ 2:45 am
« Newer PostsOlder Posts »

© 2024 GGSHOW | Powered by WordPress