WordPress Howto retrieve top parent category ID from the post

Add the following code in your theme functions.php

function is_parent_category($cats, $_post = null)
{
	foreach ((array) $cats as $cat)
	{
		$descendants = get_term_children((int) $cat, "category");
		if ($descendants && in_category($descendants, $_post))
			return true;
	}
	return false;
}

?>

Usage:
if (is_parent_category(1)) // Got true/false if parent category is 1
{
//Do something
}

horde/imp display gb2312 character interim solution

While too many gb2312 character in horde cannot converted as UTF-8, to give it a quick workaround, I’d just enforce horde to treat gb2312 encoding to gbk which is more compatible for chinese double-byte character.

Replace the lines in lib/Horde/String.php from

if (!$output && String::extensionExists(‘mbstring’)) {
$output = @mb_convert_encoding($input , $to, $from);
}

to

if (!$output && String::extensionExists(‘mbstring’)) {
if ($from == ‘gb2312’) {
$from = ‘GBK,GB2312’;
}
$output = @mb_convert_encoding($input , $to, $from);
}

MS-DOS executable (COM) file is actually chinese email

#>file mytest.txt

mytest.txt: DOS executable (COM)

reported a chinese email message as a DOS executable file

Workaround:

Comment out the line in /usr/share/file/magic

#0      byte            0xe9            DOS executable (COM)
#>0x1FE leshort         0xAA55          \b, boot code
#>6     string          SFX\ of\ LHarc  (%s)

and then rebuild it

#> rm /usr/share/file/magic.mgc

#> cd /usr/share/file/

#> file -C magic

Test it again.

#> file mytest.txt

mytest.txt: UTF-8 Unicode mail text
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=214718

Perl smtp mailer script

If your server doesn’t have SMTP or maybe you have sendmail relay problem, also if you’re reporting the problem about mail service. This script allow you send out your message through SMTP insead local sendmail.

Script Usage:

echo “Hello! Perl script” | /path/to/mailer.sh “Subject” “Receiver_Name_1” “Receiver_address_1” “Receiver_Name_2” “Receiver_address_2”
<script> | /path/to/mailer.sh “Subject” “Receiver_Name_1” “Receiver_address_1” “Receiver_Name_2” “Receiver_address_2”
Continue reading “Perl smtp mailer script”