Zen Cart Review Poster – 随机生成姓名、邮箱、评论内容、时间、评级

Zen Cart Review Poster – 随机生成姓名、邮箱、评论内容、时间、评级

===简介===
Zen Cart Review Poster是用PHP写的一个小工具,可以用来对ZenCart网店产品进行评论,能随机生成姓名、邮箱、评论内容、时间、评级,评论无需审核,按时间倒序显示,适合需要自卖自夸的店主。

===功能===
输入产品ID即可评论
评论静默提交无需跳转
随机生成姓名、邮箱、评论标题和内容(所有数据保存在.txt文件中 一行一条 我已经采集了一些 可自己添加修改)
随机生成评论时间,显示出来的评论时间是设定的时间起点如20130909至当前服务器时间这个期间随机一个时间点
自动评级4星或5星,总体评级控制在4.85星,20条评论中 5星:4星 比例为17:3 ((175+34)/20=4.85),可以自己修改。
当然你也可以修改自动生成的姓名、邮箱、评论内容、时间、评级
评论无需审核直接显示在产品页面

===使用说明===
将post-a-review-background-send.php中的http://www.domain.com/替换为自己ZEN CART网站的地址,如果你的网店产品是以-p***.html结尾的,请把_p替换为-p,(替换成别人网店地址也行,不要那么坏啊… 要是人家也没有评论验证码)
上传程序文件到你的网站任意目录,其中header_php.php需要上传到includes/modules/pages/product_info/header_php.php(请先备份原文件,或用WinMerge参照本文件修改)
访问post-a-review-background-send.php页面开始评论

—提示—
所有TXT文本中的数据都是一行一条,如果自己添加评论,不要把一条分成了N行,程序会当作N条评论的
email-list.txt 是邮箱后缀,邮件地址是随机first-name+随机last-name+随机域名生成的
有验证码的不行,另外仅测试过国内流行的那个高仿版本的ZEN CART

===评论按时间倒序排列===
评论本来是按ID r.reviews_id 排序 要做得更真一点 请修改为按评论时间 r.date_added 排序
ORDER BY r.reviews_id DESC修改为ORDER BY r.date_added DESC

前台产品页面修改评论排序涉及的文件(压缩包里也有修改好的文件)
/includes/modules/pages/product_info/main_template_vars.php
/includes/modules/pages/product_reviews/header_php.php
/includes/modules/pages/reviews/header_php.php
/includes/modules/pages/testimonials/header_php.php

后台修改评论排序是修改
/system/reviews.php

调用评论的地方
http://domain.com/testimonials.html
http://domain.com/reviews.html

/includes/modules/pages/product_reviews/header_php.php
/includes/modules/pages/reviews/header_php.php
这两个文件只影响默认主题(templates/template_default)可以不修改

===演示/下载===
演示地址:http://littlebar.tk/app/Zen-Cart-Review-Poster/post-a-review-background-send.php (网店地址没有设置…)
程序下载:http://pan.baidu.com/s/1c0esl4O#path=%252Flittle8%252F20141212-Zen-Cart-Review-Poster

===代码===
—post-a-review-background-send.php代码—

<?php
/*Zen Cart Review Poster - by @JungleHi 
URL: http://littlebar.tk/2014/12/12/
---------
artificially review any product by ID
overall 4.85 out of 5 stars
rand date/name/email/title/review content(data are included as .txt files)
background posting
auto approved
---------
How to setup?
1, replace http://www.domain.com/ with your store url
2, replace includes/modules/pages/product_info/header_php.php, or make necessary changes, so to inset date to database, and set the review_status to 1 (approved)
3, also upload the email/review/name .txt lists to where this file is uploaded.
*/

//禁止页面缓存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pramga: no-cache"); 

$ProductID = $_REQUEST['id'];//商品ID
$firtnamelist = file_get_contents('./first-name-list.txt', FILE_USE_INCLUDE_PATH);
$lastnamelist = file_get_contents('./last-name-list.txt', FILE_USE_INCLUDE_PATH);
$emaillist = file_get_contents('./email-list.txt', FILE_USE_INCLUDE_PATH);
$reviewlist = file_get_contents('./review-list.txt', FILE_USE_INCLUDE_PATH);

//echo $namelist;
//随机用户名
$FirstNameInput = explode("\n",$firtnamelist);
$rand_keys_first = array_rand($FirstNameInput, 2);
//echo $FirstNameInput[$rand_keys[0]] . "\n". '<br>';

$LastNameInput = explode("\n",$lastnamelist);
$rand_keys_last = array_rand($LastNameInput, 2);
//echo $LastNameInput[$rand_keys[0]] . "\n". '<br>';

//随机email
$EmailInput = explode("\n",$emaillist);
$rand_keys_email = array_rand($EmailInput, 2);

//随机评论内容
$ReviewInput = explode("\n",$reviewlist);
$rand_keys_review = array_rand($ReviewInput, 2);

//随机时间2013-09-09 00:00:00 到 当前服务器时间
//mktime(hour,minute,second,month,day,year,is_dst)
$data1 = mktime(00,00,00,09,09,2013);//起始时间
$data2 = mktime( );//截止时间 留空返回当前服务器时间
$rand_time = rand($data1,$data2);
//echo date("Y-m-d H:i:s",$rand_time);
$review_date = date("Y-m-d H:i:s",$rand_time);
?>

<?php
function subwords($words,$num){
	//从 $words 字符串中 截取前 $num 个单词 
	// functioned by PHP designer Hiosiao,
	$total_num = str_word_count($words); // 获取$words 中单词个数
	if($total_num <= $num){   // 如果$words 中单词个数少于 $num 
		return $words;
	}else{
		$pattern = '/([\S]+?[ ]+){'.$num.'}/';
		preg_match($pattern, $words, $out);
		return $out[0].'...'; //如果字符串过长,将以 ... 结束
	}
	}
//example
$str = 'it is a sunny day today !';
//echo subwords($str,5);
//it is a sunny day ...
//echo subwords($str,9);
//it is a sunny day today !

echo subwords($ReviewInput[$rand_keys_review[0]],5);//截取评论前5个单词为评论标题
?>

<?php
//4.85以上好评
$rating = rand(0,9);
if ($rating >= 3){$rating = 5; echo '5 stars';
}
else {$rating = rand(4,5);}
//echo $rating;//
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Zen Cart Review Poster</title>
</head>

<body onkeydown="save();">
	<h3>Background Post Reviews to Zen Cart</h3>
	<!-- includes/modules/pages/product_info/header_php.php -->
	<!-- action="http://www.domain.com/_p<?php echo $ProductID;?>.html#review" -->
	
	<hr />
	<form  target="hidden-form" method="post" action="http://www.domain.com/_p<?php echo $ProductID;?>.html#review" name="post_review">
		ProductID: <?php echo $ProductID;?><br />
		Rating: <input type="text" value="<?php echo $rating;?>" id="product_score" name="product_score" onclick="this.focus();this.select()"><br />
		<input type="hidden" value="review" id="action" name="action">
		Name: <input type="text" value="<?php echo $FirstNameInput[$rand_keys_first[0]].'.'.$LastNameInput[$rand_keys_last[0]]; ?>" name="customer_name" onclick="this.focus();this.select()">	<br />
		Date: <input type="text" value="<?php echo $review_date; ?>" name="review_date" onclick="this.focus();this.select()">	<br />
		Email: <input type="text" value="<?php echo $FirstNameInput[$rand_keys_first[0]].'.'.$LastNameInput[$rand_keys_last[0]].'@'.$EmailInput[$rand_keys_email[0]]; ?>" name="customer_email" onclick="this.focus();this.select()" />	<br />
		Title: <input tabindex="1" type="text" value="" name="review_title" onclick="this.focus();this.select()">	<br />
		Review Content: <br />
		<textarea class="textarea1" name="review_content" id="txt_review" style="margin: 2px; height: 240px; width: 500px;" ><?php echo stripslashes($ReviewInput[$rand_keys_review[0]]); ?></textarea> <br />
		<button type="submit">Submit</button>
	</form>
	
	<script> 
	post_review.review_title.focus(); //光标定位在评论内容
	</script> 

	<!--隐藏的评论form target -->
	<IFRAME style="display:none" name="hidden-form"></IFRAME>

	<hr />
	<!--poster页面的表单 method="post"会导致浏览器提示表单重复发送 -->
	<form method="get" action="post-a-review-background-send.php?id=<?php echo $ProductID+1;?>" name="next-poster">
		<input type="text" value="<?php echo $ProductID+1; ?>" name="id" >
		<button tabindex="2" type="submit" style="width:200px; height:25px">review Next Product <?php echo $ProductID+1; ?> </button>
	</form>

	<hr />
	<p>操作说明备忘,指定ID后进入页面直接ENTER键提交,页面静默提交后ESC,再刷新,再提交,按TABLE键后ENTER评论下一个商品(随机生成姓名、邮箱、评论内容、时间、评级)<br />
	Code by <a href="http://littlebar.tk/2014/12/12/">@JungleHi</a>
	</p>

</body>
</html>

—header_php.php有修改部分的代码—

 // This should be first line of the script:
  $zco_notifier->notify('NOTIFY_HEADER_START_PRODUCT_INFO');

  require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
  if ($_POST['action']){
    if (!empty($_REQUEST['review_date'])) {
      $review_status = '1'; //如果有提交review_date则通过审核
    } elseif ( REVIEWS_APPROVAL == '1' ){
	  $review_status = '0'; 
	}
	else {
      $review_status = '1';
    }
  	$sql_data_array =array();
    $sql_data_array2 =array(); 	
  	$customer_id = isset($_SESSION['customer_id']) ? $_SESSION['customer_id']:'';
  	$reviews_rating = $_POST['product_score'];
	if( !empty($_REQUEST['review_date']) ){
	$reviews_date = $_POST['review_date'];
	} else {
		$reviews_date = date("Y-m-d h:i:s");//如没有提交时间 则使用当前服务器时间
	}

  	$customer_name = isset($_SESSION['customer_id']) ? zen_get_customer_name($_SESSION['customer_id']):$_POST['customer_name'];
  	$customer_email = isset($_SESSION['customer_id']) ? zen_get_customer_email($_SESSION['customer_id']):$_POST['customer_email'];
    $review_title = $_POST['review_title'];
    $review_content = $_POST['review_content'];
    $sql = "INSERT INTO " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, customers_email, reviews_rating, date_added, status)
			VALUES (:productsID, :customersID, :customersName, :customersEmail, :rating, :review_date, " . $review_status . ")";



    $sql = $db->bindVars($sql, ':productsID', $_GET['products_id'], 'integer');
    $sql = $db->bindVars($sql, ':customersID', $customer_id, 'integer');
    $sql = $db->bindVars($sql, ':customersName', $customer_name, 'string');
    $sql = $db->bindVars($sql, ':customersEmail', $customer_email, 'string');
    $sql = $db->bindVars($sql, ':rating', $reviews_rating, 'string');
	$sql = $db->bindVars($sql, ':review_date', $reviews_date, 'date');
	
    
    $db->Execute($sql);
    $insert_id = $db->insert_ID();
    $sql = "INSERT INTO " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text, reviews_title)
            VALUES (:insertID, :languagesID, :reviewText, :reviews_title)";

    $sql = $db->bindVars($sql, ':insertID', $insert_id, 'integer');
    $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
    $sql = $db->bindVars($sql, ':reviewText', $review_content, 'string');
    $sql = $db->bindVars($sql, ':reviews_title', $review_title, 'string');

    $db->Execute($sql);
    
  	$messageStack->add('reviews',TEXT_WRITE_REVIEW_SUCCESS,'success');
  	unset($_POST);
  }
  ...
4 Comments

Add a Comment

Your email address will not be published.