- ชื่อ: Word Count Limits
- ผู้เขียน: ethankcvds
- นำเสนอโดย: DexMoreGroup
- ประเภท: Posting
- รองรับ: SMF 1.1.xx, 2.0.xx
- ปรับปรุงล่าสุด: 13 กุมภาพันธ์ 2554
- ต้นฉบับ: Word Count Limits
รายละเอียด กำหนดจำนวนคำต่ำสุด และสูงสุดในการตั้งกระทู้ เพื่อป้องกันการตอบด้วยประโยคสั้นๆ เช่น ขอบคุณ, แหล่มเลย, thank ฯลฯ และมีเพียงสัญลักษณ์แสดงอารมณ์ โดยสามารถกำหนดหรือไม่กำหนดจำนวนคำเฉพาะบอร์ดได้อย่างอิสระ
ตัวอย่าง
สำหรับ SMF 1.1.xxแก้ไขไฟล์:file $themedir/ManageBoards.template.php
ค้นหา -->>
if (empty($modSettings['permission_enable_by_board']))
เพิ่มไว้ก่อน -->>
// Add the min/max word items
echo '
<tr>
<td>
<b>', $txt['limit_min_words'], '</b><br />', $txt['limit_words_note'], '
<br /><br />
</td>
<td valign="top" align="right">
<input type="text" name="min_words" value="', $context['board']['min_words'], '" size="5" />
</td>
</tr><tr>
<td>
<b>', $txt['limit_max_words'], '</b><br />', $txt['limit_words_note'], '
<br /><br />
</td>
<td valign="top" align="right">
<input type="text" name="max_words" value="', $context['board']['max_words'], '" size="5" />
</td>
</tr>';
file $sourcedir/ManageBoards.php
ค้นหา -->>
'permission_mode' => 'normal',
เพิ่มไว้หลัง -->>
'min_words' => 0,
'max_words' => 0,
ค้นหา -->>
// Checkboxes....
เพิ่มไว้ก่อน -->>
$boardOptions['min_words'] = abs((int) $_POST['min_words']);
if($boardOptions['min_words'] > 10000) {
$boardOptions['min_words'] = 10000;
}
$boardOptions['max_words'] = abs((int) $_POST['max_words']);
if($boardOptions['max_words'] > 10000) {
$boardOptions['max_words'] = 10000;
}
file $sourcedir/Subs-Boards.php
ค้นหา -->>
b.ID_THEME, b.override_theme,
เพิ่มไว้หลัง -->>
b.min_words, b.max_words,
ค้นหา -->>
'override_theme' => $row['override_theme'],
เพิ่มไว้หลัง -->>
'min_words' => $row['min_words'],
'max_words' => $row['max_words'],
ค้นหา -->>
// Set the theme for this board.
เพิ่มไว้ก่อน -->>
if (isset($boardOptions['min_words']))
$boardUpdates[] = 'min_words = ' . abs((int) $boardOptions['min_words']);
if (isset($boardOptions['max_words']))
$boardUpdates[] = 'max_words = ' . abs((int) $boardOptions['max_words']);
file $sourcedir/Post.php
ค้นหา -->>
// Validate the poll...
เพิ่มไว้ก่อน -->>
// Now, let's check the post for being too short/tall
$query = db_query("
SELECT min_words, max_words FROM {$db_prefix}boards WHERE ID_BOARD = {$board_info['id']}
", __FILE__, __LINE__);
if(mysql_num_rows($query) == 1) {
list($min_words, $max_words) = mysql_fetch_row($query);
if($min_words > 0 || $max_words > 0) {
$count = wordcount( $func['htmltrim'](strip_tags(parse_bbc($_POST['message'], false))) ); // convert everything to HTML then scrap it to get only content
if($min_words != 0 && $count < $min_words) {
$post_errors[] = 'post_too_few_words';
} elseif($max_words != 0 && $count > $max_words) {
$post_errors[] = 'post_too_many_words';
}
}
}
mysql_free_result($query);
ค้นหา -->>
?>
เพิ่มไว้ก่อน -->>
function wordcount($str) {
$str = strip_tags(parse_bbc($str));
$str = un_htmlspecialchars($str);
$str = preg_replace("/[\x80-\xFF]/", "x", $str);
// attempt the clever version
$count = 0;
$count = @preg_match_all("/\p{L}[\p{L}\p{Mn}'\x{2019}]{2,}/u", $str, $matches);
if($count == 0) {
// can mean this one failed, so fallback
$str = preg_replace("/[\x21-\x26\x28-\x40\x5B-\x60\x7B-\x7F]/", " ", $str);
$count = 0;
$words = str_word_count($str, 1); // but this doesn't give us min 3 letters!
foreach($words as $word) {
if(strlen($word) >= 3)
$count++;
}
}
return $count;
}
file $languagedir/Modifications.thai-utf8.php
เพิ่ม -->>
ขออภัย! ส่วนนี้สงวนไว้เฉพาะสมาชิกเท่านั้น กรุณา เข้าสู่ระบบ หรือ ลงทะเบียนfile $languagedir/Errors.thai-utf8.php
เพิ่ม -->>
ขออภัย! ส่วนนี้สงวนไว้เฉพาะสมาชิกเท่านั้น กรุณา เข้าสู่ระบบ หรือ ลงทะเบียนสร้างไฟล์: install11.php เพื่อสร้างฐานข้อมูล ไว้ใน $boarddir (ที่เดียวกับไฟล์ SSI.php) รัน http://www.your_url.xxx/$boarddir/install11.php -->> Enter เสร็จแล้วลบทิ้ง
<?php
if (!defined('SMF')) {
if(file_exists(dirname(__FILE__) . '/SSI.php'))
include_once(dirname(__FILE__) . '/SSI.php');
else
die('<strong>Error</strong>: Please make sure you have SSI.php in your root directory.');
}
global $db_prefix;
$min = true; $max = true;
$query = db_query("SHOW COLUMNS FROM {$db_prefix}boards LIKE '%words'", __FILE__, __LINE__);
while($row = mysql_fetch_row($query)) {
if($row[0] == 'min_words')
$min = false;
if($row[0] == 'max_words')
$max = false;
}
if($min)
db_query("ALTER TABLE {$db_prefix}boards ADD min_words SMALLINT(5) NOT NULL DEFAULT '0'", __FILE__, __LINE__);
if($max)
db_query("ALTER TABLE {$db_prefix}boards ADD max_words SMALLINT(5) NOT NULL DEFAULT '0'", __FILE__, __LINE__);
?>
การตั้งค่า: ผู้ดูแล -->> แก้ไขบอร์ด -->> [ชื่อบอร์ด] แก้ไข
ลิงค์หัวข้อ:
http://dexmore.com/topic/5130