2009/04/27

How to auto post to Wordpress

  1. Turn on remove_posting at http://yourdomain/wp-admin/options-writing.php
  2. Using below PHP code:
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
   $categories = implode(",", $categories);
   $XML = "<title>$title</title>".
   "<category>$categories</category>".
   "<body>$body</body>";
   $params = array('','',$username,$password,$XML,1);
   $request = xmlrpc_encode_request('blogger.newPost',$params);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
   curl_setopt($ch, CURLOPT_URL, $rpcurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 1);
   curl_exec($ch);
   curl_close($ch);
}

2009/04/14

mySQL date function

The SQL to get total order number and total order amount from orders table:

SELECT count(*), sum(order_total) 
FROM orders 
WHERE DAYOFMONTH(last_accessed) = DAYOFMONTH(now()) 
      AND MONTH(last_accessed) = MONTH(now()) 
      AND YEAR(last_accessed) = YEAR(now()) 
      AND record_state = 1

Note:

  1. DAYOFMONTH is synonym of DAY used to get day (ex: 1-31) from a data and time string (ex: 2009-04-14 11:44:02)
  2. Complete mysql date function can be found at here

2009/03/30

Links is forced to open in a new window

All HTML links with target="_blank" usually means open in a new window. Some modern browser can open them in a new tab, which is one of enhancements that make Firefox famous.

But recently, the links of the page are forced to open in a new window other tan a new tab in my Firefox browser, although I have set it to open in a new tab in the Tools->option-tab.

I tried to Goolge an answer, but found nothing. Finally, I found the reason.

Try enter ‘about:config’ on your Firefox browser address bar, you will see a long list, type in ‘link’ in the Filter, you will see, below two parameters,

browser.link.open_newwindow and browser.link.open_newwindow.restriction

The default value of these two parameters are 3 and 2. But they were 1 and 1 on my browser.

browser.link.open.newwindow = 1 means open All HTML links with target="_blank" in a new tab, but it only work when browser.link.open_new.restriction = 2.

2009/03/24

iconv_substr() gives "Unknown error"

If Unknown error(0), then most likely it is this issue, iconv_substr() gives "Unknown error" when string length = 1" and it was fixed in PHP5.2, if you are still using PHP5.1, here is a workaround for this bug,

/*Reproduce code:
---------------*/
$s = 'x';
$s = iconv_substr($s, 0, 1, 'UTF-8');
var_dump($s);
/*Expected result:
----------------*/
string(1) "x"
/*Actual result:
--------------*/
bool(false)
//and Notice: iconv_substr() [function.iconv-substr.html]: Unknown error
//(0) in ...
/*A workaround:
-------------*/
$s = 'x';
$s .=" "; //add one more empty character
$s = iconv_substr($s, 0, 1, 'UTF-8');

But if you got Unknown error(12), which is what I got in lucene search engine. Then it is a issue in this thread, but don’t know the solution yet.

2009/03/20

Some https conf for sercurity

#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature Off
#Fri Mar 20 09:19:57 EDT 2009: per OReilly
ServerTokens ProductOnly

#
# Timeout: The number of seconds before receives and sends time out.
#
#Fri Mar 20 09:12:45 EDT 2009: Timeout 180  (reduced  per O'Reilly recommendation for DOS protection)
Timeout 60

Sessioin stuff

Session cookie lifetime in our server is 864000 sec, so it is 10days not 30minutes as we always assume.

When people logon online account,

  • 1. get billing/shipping info in account_billing/account_shipping table.
  • 2. then check if there is billing/shipping info in the billing/shipping table with the same session_id.
  • 3. if yes in step2, then update it with the one got from step1; if not, then insert with one got from step one if found in the step 1

2009/03/19

Trademark, Copyright, and Register symbols

Trademark, copyright, and register symbols in iso-8895-1 character set cannot be displayed correctly in other character set, for example, urf-8, or even iso-8895-15.

Try this function, which should fix this issue.

function tcr_encode($str) {
   $str = preg_replace("/".chr(153)."/",'&trade;',$str); // trademark
   $str = preg_replace("/".chr(174)."/",'&reg;',$str); // registered tratemark
   $str = preg_replace("/".chr(169)."/",'&copy;',$str); // copyright
   return $str;
}
//change trademark, copyright, and register symbols to html entity
$title = tcr_encode($title);