如何停止wordpress 評論pingback

煩人的垃圾pingback 評論占用了系統大部份的空間

可以在控制台的Setting > discussion 把第二項取消 :

DisableTrackbacksCompletelyonWordpress

 

舊有的刪除需要到MYSQL 運行語句一次過清掉 :

DELETE FROM wp_options WHERE option_name LIKE ('_transient_%');
DELETE FROM wp_comments WHERE wp_comments.comment_type = 'pingback';
DELETE FROM wp_comments WHERE wp_comments.comment_type = 'trackback';
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';

How to install Memcached on Windows machine

After some research I found that there is a Win32 binary version of memcached available here.

So go there and download win32 binary version to your computer. When downloaded, extract the file to folder memcahced on your C partition.

You should get only one file named memcached.exe. Now we need to install this as a service, as memCached is daemon and should be run only as service.

To install Memcached as a service, follow these steps (please change all forward slashes to backslashes):

  1. If you’re running Vista, you should set memcached.exe to Run as administrator
  2. Install the service using the command:
    1 c:/memcached/memcached.exe  -d install

    from the command prompt

  3. Start the server from the Services or by running one of the following commands:
    1 c:/memcached/memcached.exe -d  start

    or

    1 net start "memcached Server"

That is it, now your memcached server is installed and is listening to port 11211. There is one more thing left to do. By default, server is set to 64Mb memory limit, which is too small. To correct, go to Registry Editor and find key

1 HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached  Server .

Change the ImagePath entry to:

1 “C:/memcached/memcached.exe” -d runservice -m 512

This way you will use 512 Mb memory limit for your server.

Google Client auth Login with PHP and Curl

// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE",
    "Email" => "[email protected]",
    "Passwd" => "yourgooglepassword",
    "service" => "writely",
    "source" => "your application name"
);

// Initialize the curl object
$curl = curl_init($clientlogin_url);

// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Execute
$response = curl_exec($curl);

// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];

echo "The auth string is: " . $auth;
// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
    "Authorization: GoogleLogin auth=" . $auth,
    "GData-Version: 3.0",
);

// Make the request
curl_setopt($curl, CURLOPT_URL, "{Google service feed link}");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);

$response = curl_exec($curl);
curl_close($curl);

// Parse the response
$response = simplexml_load_string($response);

echo "<pre>";
print_r($response); 
echo "</pre>";

phpExcel Class

phpExcel,操作excel很方便,尤其是可以方便的加入圖片,支持jpg gif png格式。

下載地址:http://www.codeplex.com/PHPExcel

下面是總結的幾個使用方法

 

include 'PHPExcel.php';

include 'PHPExcel/Writer/Excel2007.php';

//或者include 'PHPExcel/Writer/Excel5.php'; 用於輸出.xls的

//創建一個excel

$objPHPExcel = new PHPExcel();

//保存excel—2007格式

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

//或者$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); 非2007格式

$objWriter->save("xxx.xlsx");

//直接輸出到瀏覽器

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);

header("Pragma: public");

header("Expires: 0");

header("Cache-Control:must-revalidate, post-check=0, pre-check=0");

header("Content-Type:application/force-download");

header("Content-Type:application/vnd.ms-execl");

header("Content-Type:application/octet-stream");

header("Content-Type:application/download");;

header('Content-Disposition:attachment;filename="resume.xls"');

header("Content-Transfer-Encoding:binary");

$objWriter->save('php://output');

——————————————————————————————————————–

//設置excel的屬性:

//創建人

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");

//最後修改人

$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");

//標題

$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");

//題目

$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");

//描述

$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");

//關鍵字

$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");

//種類

$objPHPExcel->getProperties()->setCategory("Test result file");

——————————————————————————————————————–

//設置當前的sheet

$objPHPExcel->setActiveSheetIndex(0);

//設置sheet的name

$objPHPExcel->getActiveSheet()->setTitle('Simple');

//設置單元格的值

$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String');

$objPHPExcel->getActiveSheet()->setCellValue('A2', 12);

$objPHPExcel->getActiveSheet()->setCellValue('A3', true);

$objPHPExcel->getActiveSheet()->setCellValue('C5', '=SUM(C2:C4)');

$objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C5)');

//合併單元格

$objPHPExcel->getActiveSheet()->mergeCells('A18:E22');

//分離單元格

$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');

//保護cell

$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // Needs to be set to true in order to enable any worksheet protection!

$objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');

//設置格式

// Set cell number formats

echo date('H:i:s') . " Set cell number formats\n";

$objPHPExcel->getActiveSheet()->getStyle('E4')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);

$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4'), 'E5:E13' );

//設置寬width

// Set column widths

$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);

$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);

//設置font

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setName('Candara');

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20);

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);

$objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);

$objPHPExcel->getActiveSheet()->getStyle('D13')->getFont()->setBold(true);

$objPHPExcel->getActiveSheet()->getStyle('E13')->getFont()->setBold(true);

//設置align

$objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

$objPHPExcel->getActiveSheet()->getStyle('D12')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

$objPHPExcel->getActiveSheet()->getStyle('D13')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);

//垂直居中

$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

//設置column的border

$objPHPExcel->getActiveSheet()->getStyle('A4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

$objPHPExcel->getActiveSheet()->getStyle('B4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

$objPHPExcel->getActiveSheet()->getStyle('C4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

$objPHPExcel->getActiveSheet()->getStyle('D4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

$objPHPExcel->getActiveSheet()->getStyle('E4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

//設置border的color

$objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getLeft()->getColor()->setARGB('FF993300');

$objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getTop()->getColor()->setARGB('FF993300');

$objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getBottom()->getColor()->setARGB('FF993300');

$objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getTop()->getColor()->setARGB('FF993300');

$objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getBottom()->getColor()->setARGB('FF993300');

$objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getRight()->getColor()->setARGB('FF993300');

//設置填充顏色

$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);

$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('FF808080');

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setARGB('FF808080');

//加圖片

$objDrawing = new PHPExcel_Worksheet_Drawing();

$objDrawing->setName('Logo');

$objDrawing->setDescription('Logo');

$objDrawing->setPath('./images/officelogo.jpg');

$objDrawing->setHeight(36);

$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

$objDrawing = new PHPExcel_Worksheet_Drawing();

$objDrawing->setName('Paid');

$objDrawing->setDescription('Paid');

$objDrawing->setPath('./images/paid.png');

$objDrawing->setCoordinates('B15');

$objDrawing->setOffsetX(110);

$objDrawing->setRotation(25);

$objDrawing->getShadow()->setVisible(true);

$objDrawing->getShadow()->setDirection(45);

$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

//在默認sheet後,創建一個worksheet

echo date('H:i:s') . " Create new Worksheet object\n";

$objPHPExcel->createSheet();

$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');

$objWriter-save('php://output');

 

Warning: Call-time pass-by-reference has been deprecated的解决办法

问题提示如下:
Warning: Call-time pass-by- reference has been deprecated – argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name] (). If you would like to enable call-time pass-by- reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in c:\crm203 \modules\Reports\Report.php on line 370
修改 PHP.ini,allow_call_time_pass_reference = On。实际上,我在安装了Apache/2.0.58 (Win32) PHP/4.4.2,这个选项缺省是打开的,另外,我记得有朋友说另一个解决的办法是关闭错误报告功能。实际上,将上述php配置文件的值设为on可以视做一个解决的办法,但关闭报告功能估计是一种自己骗自己的方法,因为这是一个大的错误,不让他显示并不代表就可以解决掉。
我在解决这一问题中发现,一共有几个原因可能导致上述问题:
1.上述值被设置了off。解决方法:修改PHP.ini,allow_call_time_pass_reference = On。
2.如果你在windows下安装,而php安装目录 everyone没有读与执行的权限,可能也会导致这个问题;
3.如果php配置中的session目录设置不正确,也可能导致这一问题。包括配置文件中路径设置不正确和没有创建session数据目录;
4.如果php配置中的includes目录设置不正确,也可能导致这一问题。包括配置文件中中路径配置不正确和没有创建includes这个目录。
上述后三种情况,多数apache+php配置说明都有详细的描述,大家可以参考。

上面这个问题,通常发生在不使用vTigerCRM的安装程序,而是自己手工安装apache+php+mysql中,比如使用单独的安装文件或者easyphp安装包。都很有可能出现上述的问题。  上面是我在解决这些问题时一些经验,不一定有代表性,只希望大家在解决类似问题时提供一些参考。

php.ini中allow_call_time_pass_reference参数的意思

从php手册中可以找到:allow_call_time_pass_reference boolean

是否启用在函数调用时强制参数被按照引用传递。此方法已不被赞成并在 PHP/Zend 未来的版本中很可能不再支持。鼓励使用的方法是在函数定义中指定哪些参数应该用引用传递。鼓励大家尝试关闭此选项并确保脚本能够正常运行,以确保该脚本也能在未来的版本中运行(每次使用此特性都会收到一条警告,参数会被按值传递而不是按照引用传递)。

在函数调用时通过引用传递参数是不推荐的,因为它影响到了代码的整洁。如果函数的参数没有声明作为引用传递,函数可以通过未写入文档的方法修改其参数。要避免其副作用,最好仅在函数声明时指定那个参数需要通过引用传递。

当allow_call_time_pass_reference=Off时<?php
function abc($a,$b){
echo “$a\n”;
echo “$b\n”;
$b = ‘cde’;
}

$a = ‘abc’;
$b = “bcd”;
//不好的用法,会引发一个php warnning
abc($a ,&$b);

echo “$b\n”;
?>要想通过引用来传递参数$b,程序可改为<?php
function abc($a,& $b){
echo “$a\n”;
echo “$b\n”;
$b = ‘cde’;
}

$a = ‘abc’;
$b = “bcd”;
//正确的用法
abc($a ,$b);

echo “$b\n”;
//output is:
//abc
//bcd
//cde
?>

 

PHP Google Translate function

function google_trans($text,$sl = ‘en’,$tl = ‘zh-TW’)
{
$url = “http://translate.google.com.hk/translate_t?sl={$sl}&tl={$tl}&text=”.urlencode($text);
ini_set ( “user_agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)” );
if(@$HTML = file_get_contents($url))
{
$tt0 = split(‘

‘,$HTML);
$tt1 = split(‘

‘,$tt0[1]);
return $tt1[0];
}
else
return false;
}

PayPal Set Up for VirtueMart

How do I install PayPal?
You don’t have to install it. PayPal is a part of the official distribution and installed per default.
You just have to go to “Store” => “Payment method list” and click on “PayPal”.
If you want to know which files are responsible for PayPal:
VIRTUEMART:
* /site_root/administrator/components/com_virtuemart/notify.php
This is the script where paypal.com should post to when a transaction is made. If the transaction was VERIFIED, the order status is usually update to the oder status you have set in the configuration (you can set that for Confirmed, Pending & Failed payments).
* /site_root/administrator/components/com_virtuemart/classes/payment/ps_paypal.php
This is the main class for the paypal configuration. It actually doesn’t play any role on checkout.
* site_root/administrator/components/com_virtuemart/classes/payment/ps_paypal.cfg.php
The configuration file for the paypal settings. Remember that this file must be writable to save changes to the configuration.

How do setup PayPal?
This payment method is to be set up as every other payment method: go to “Store” => “List Payment Methods”, then select “PayPal” from the list. Once the payment method form for PayPal has opened, you can activate/deactivate it, rename it (the name of the payment method doesn’t really matter!), restrict it to a shopper group, define a discount value and change the method’s position in a list with other payment methods (list order).
Please note that there’s an important Configuration Panel, which can be reached by clicking on the Tab Heading “Configuration”.
Test Mode [yes/no; default=no]
When you enable the test mode, you can debug the script using Eliteweaver’s ipn testing environment. Last time I used that, i didn’t worked and didn’t recognize that the script was posting back (I know it did!). This is NOT FOR THE PAYPAL SANDBOX!
PayPal Email
Your business email, which is your login at paypal (or paypal sandbox).
Order Status for confirmed Payments
Order Status for Pending Payments
Order Status for failed Payments

With these settings you can define, which Order Status should be set when a payment was successful / is pending / has failed.
IMPORTANT: PayPal seems to return “Pending” very often, although the payment will be no problem. A further investigation, why the payment is still pending is not made at this time (we’ll have to improve the paypal notify script to check that).
That’s why you see “An error occured while processing your transaction. The status of your order could not be updated“: You obviously haven’t set the Order Status for pending payments to “confirmed”.
Payment Extra Info
The textarea is used by each payment method. You can fill in HTML/PHP/Javascript here. It is executed:
* on the “Thankyou” page
* each time the order is viewed by the customer (and it’s order status is not “confirmed”)
So you can use it to
* process additional affiliate tasks
* show your bank account details
* whatever you want to display to the customer
I have rewritten the Payment Extrainfo Code for PayPal, so i directly redirects the customer to PayPal after clicking on “Confirm” to place the order. Just copy and paste it into your PayPal Extrainfo box.
CODE FOR USE IN VIRTUEMART

Code:
<?php
$db1 = new ps_DB();
$q "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$user->country."' ORDER BY country_2_code ASC";
$db1->query($q);

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");
$post_variables = Array(
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').": "$db->f("order_id"),
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"currency_code" => $_SESSION['vendor_currency'],

"address_override" => "1",
"first_name" => $dbbt->f('first_name'),
"last_name" => $dbbt->f('last_name'),
"address1" => $dbbt->f('address_1'),
"address2" => $dbbt->f('address_2'),
"zip" => $dbbt->f('zip'),
"city" => $dbbt->f('city'),
"state" => $dbbt->f('state'),
"country" => $db1->f('country_2_code'),
"email" => $dbbt->f('user_email'),
"night_phone_b" => $dbbt->f('phone_1'),
"cpp_header_image" => $vendor_image_url,

"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_shipping" => "1",
"no_note" => "1"
);
if( $page == "checkout.thankyou" ) {
$query_string "?";
foreach( $post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
vmRedirect$url $query_string );
} else {
echo '<form action="'.$url.'" method="post" target="_blank">';
echo '<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Click to pay with PayPal - it is fast, free and secure!" />';

foreach( $post_variables as $name => $value ) {
echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />';
}
echo '</form>';

}
?>

If you don’t want your customer to be redirected after confirmation, but still want him to click on “Pay with PayPal”, change

Code:
if( $page == "checkout.thankyou" ) {

to

Code:
if( false ) {

Don’t forget to save all your changes.  Roll Eyes
Common Questions
My PayPal doesn’t work. What’s wrong?
It could be anything. Please review your settings and read the other Questions/Answers.
How can I use the PayPal Sandbox for debugging my PayPal Payment Method?
This is really easy: you just need to change the payment extrainfo in the payment method form for PayPal:
Change

Code:
$url = "https://www.paypal.com/cgi-bin/webscr";

to

Code:
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";

and save. Please remember: DO NOT TURN ON DEBUG MODE WHEN WORKING WITH THE SANDBOX!
I’m getting the message “An error occured while processing your transaction. The status of your order could not be updated.” when returning from PayPal.
Please be careful before you blame VirtueMart.
There are many reasons why this message could be displayed.

  • Your script can’t be reached from the internet
    It’s important that your notify.php is not protected by .htaccess files (which is the case when you secure your /administrator directory).
    Try to point to it with your browser.
  • There’s a parsing error in your script.
    If you have no idea why things go wrong, do the following:
    * Enable Debug Mode
    * Go to http://www.eliteweaver.co.uk/testing/ipntest.php and debug your script.
    * Click on “Follow IPN” after you have clicked on “Submit IPN” to see the real debug output of your notify.php script
  • Your Payment returned the payment status “Pending” or “Failed”.
    When you have a pending or failed payment, the notify.php script changes the order status to whatever you have set in the paypal configuration for it. BUT: if this isn’t “confirmed”, you will see this error message.

How can I change the return page?
The file behind that default return page is
/site_root/administrator/components/com_virtuemart/html/checkout.result.php
You can also change the return page in the payment extrainfo in the payment method form for PayPal or set your own Notify URL in your PayPal Account.
I hope that clears it a little bit.