มี.ค 29, 2024, 05:37 ก่อนเที่ยง

ข่าว:

SMF - เพิ่งติดตั้ง!


วิธีเพิ่มความยาวตัวอักษรของหัวข้อกระทู้

เริ่มโดย Annop, พ.ย 08, 2021, 09:15 ก่อนเที่ยง

หัวข้อก่อนหน้า - หัวข้อถัดไป

Annop


วิธีเพิ่มความยาวตัวอักษรของหัวข้อกระทู้

โดยปรกติหัวข้อกระทู้จะตั้งได้ยาว 80 ตัวอักษรภาษาอังกฤษ แต่ถ้าเป็นภาษาไทยจะได้ไม่ถึง 80 ตัวอักษรจริงๆ
ทำให้อาจน้อยเกินไปจนไม่ค่อยสื่อความหมายสำหรับภาษาไทย เรามีวิธีเพิ่มความยาวตัวอักษรของหัวข้อกระทู้ดังนี้

แก้ไขไฟล์ Post.template.php ที่อยู่ใน Themes/default/Post.template.php

// Now show the subject box for this post.
   echo '
      <dt>
         <span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
      </dt>
      <dd>
         <input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" [glow=red,2,300]maxlength="80"[/glow] class="input_text" />
      </dd>
      <dt class="clear_left">
         ', $txt['message_icon'], ':
      </dt>
      <dd>

ลองแก้ maxlength จาก 80 เป็น 200 ดูนะครับ

// Now show the subject box for this post.
   echo '
      <dt>
         <span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
      </dt>
      <dd>
         <input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" [glow=red,2,300]maxlength="200"[/glow] class="input_text" />
      </dd>
      <dt class="clear_left">
         ', $txt['message_icon'], ':
      </dt>
      <dd>

บางคนทำแค่นี้ก็ใช้ได้ (อาจเป็น Version อื่น) แต่ของผมต้องแก้อีกไฟล์นึงครับที่ไฟล์ Post.php ที่อยู่ใน Sources/Post.php อีก 2 ที่คือ

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > [glow=red,2,300]100[/glow])
   $form_subject = $smcFunc['substr']($form_subject, 0, [glow=red,2,300]100[/glow]);

และ

// At this point, we want to make sure the subject isn't too long.
if ($smcFunc['strlen']($_POST['subject']) > [glow=red,2,300]100[/glow])
   $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, [glow=red,2,300]100[/glow]);


แก้จาก 100 เป็น 200 ครับ

// Make sure the subject isn't too long - taking into account special characters.
if ($smcFunc['strlen']($form_subject) > [glow=red,2,300]200[/glow])
   $form_subject = $smcFunc['substr']($form_subject, 0, [glow=red,2,300]200[/glow]);

และ

// At this point, we want to make sure the subject isn't too long.
if ($smcFunc['strlen']($_POST['subject']) > [glow=red,2,300]200[/glow])
   $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, [glow=red,2,300]200[/glow]);


แก้ได้มากที่สุดคือ 255 นะครับ เท่านี้ก็เพิ่มความยาวตัวอักษรของหัวข้อกระทู้ได้ยาววววว......แล้วครับ

เครดิตจาก
How to increase the Subject length
http://www.simplemachines.org/community/index.php?topic=359405.0

Annop


สำหรับรุ่น SMF 2.1 RC2 แก้ที่ 2 ไฟล์เดิมดังนี้

แก้ไขไฟล์ Post.template.php ที่อยู่ใน Themes/default/Post.template.php

ลองใช้ Find
maxlength="80"
พบ 2 แห่ง แต่แก้ที่เดียว อันหลัง ตามนี้

/**
 * Prints the input fields in the form's header (subject, message icon, guest name & email, etc.)
 *
 * Mod authors can use the 'integrate_post_end' hook to modify or add to these (see Post.php).
 *
 * Theme authors can customize the output in a couple different ways:
 * 1. Change specific values in the $context['posting_fields'] array.
 * 2. Add an 'html' element to the 'label' and/or 'input' elements of the field they want to
 *    change. This should contain the literal HTML string to be printed.
 */
function template_post_header()
{
   global $context, $txt;

   // Sanity check: submitting the form won't work without at least a subject field
   if (empty($context['posting_fields']['subject']) || !is_array($context['posting_fields']['subject']))
   {
      $context['posting_fields']['subject'] = array(
         'label' => array('html' => '<label for="subject" id="caption_subject">' . $txt['subject'] . '</label>'),
         'input' => array('html' => '<input type="text" name="subject" value="' . $context['subject'] . '" size="80" [glow=red,2,300]maxlength="80"[/glow] required>')
      );
   }

   // THEME AUTHORS: Above this line is a great place to make customizations to the posting_fields array

แก้ maxlength จาก 80 เป็น 200 ครับ

/**
 * Prints the input fields in the form's header (subject, message icon, guest name & email, etc.)
 *
 * Mod authors can use the 'integrate_post_end' hook to modify or add to these (see Post.php).
 *
 * Theme authors can customize the output in a couple different ways:
 * 1. Change specific values in the $context['posting_fields'] array.
 * 2. Add an 'html' element to the 'label' and/or 'input' elements of the field they want to
 *    change. This should contain the literal HTML string to be printed.
 */
function template_post_header()
{
   global $context, $txt;

   // Sanity check: submitting the form won't work without at least a subject field
   if (empty($context['posting_fields']['subject']) || !is_array($context['posting_fields']['subject']))
   {
      $context['posting_fields']['subject'] = array(
         'label' => array('html' => '<label for="subject" id="caption_subject">' . $txt['subject'] . '</label>'),
         'input' => array('html' => '<input type="text" name="subject" value="' . $context['subject'] . '" size="80" [glow=red,2,300]maxlength="200"[/glow] required>')
      );
   }

   // THEME AUTHORS: Above this line is a great place to make customizations to the posting_fields array

แก้ไขไฟล์ Post.php ที่อยู่ใน Sources/Post.php อีก 2 ที่

ลองใช้ Find
Make sure the subject isn't too long
พบ 2 แห่งคือ

// In order to keep the approval status flowing through, we have to pass it through the form...
      $context['becomes_approved'] = empty($_REQUEST['not_approved']);
      $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
      $context['can_announce'] &= $context['becomes_approved'];

      // Set up the inputs for the form.
      $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
      $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);

      // Make sure the subject isn't too long - taking into account special characters.
      if ($smcFunc['strlen']($form_subject) > [glow=red,2,300]100[/glow])
         $form_subject = $smcFunc['substr']($form_subject, 0, [glow=red,2,300]100[/glow]);

และ
// Add special html entities to the subject, name, and email.
   $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
   $_POST['guestname'] = $smcFunc['htmlspecialchars']($_POST['guestname']);
   $_POST['email'] = $smcFunc['htmlspecialchars']($_POST['email']);
   $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));

   // At this point, we want to make sure the subject isn't too long.
   if ($smcFunc['strlen']($_POST['subject']) > [glow=red,2,300]100[/glow])
      $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, [glow=red,2,300]100[/glow]);


แก้จาก 100 เป็น 200 ครับ

// In order to keep the approval status flowing through, we have to pass it through the form...
      $context['becomes_approved'] = empty($_REQUEST['not_approved']);
      $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : 0;
      $context['can_announce'] &= $context['becomes_approved'];

      // Set up the inputs for the form.
      $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
      $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);

      // Make sure the subject isn't too long - taking into account special characters.
      if ($smcFunc['strlen']($form_subject) > [glow=red,2,300]200[/glow])
         $form_subject = $smcFunc['substr']($form_subject, 0, [glow=red,2,300]200[/glow]);

และ
// Add special html entities to the subject, name, and email.
   $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
   $_POST['guestname'] = $smcFunc['htmlspecialchars']($_POST['guestname']);
   $_POST['email'] = $smcFunc['htmlspecialchars']($_POST['email']);
   $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));

   // At this point, we want to make sure the subject isn't too long.
   if ($smcFunc['strlen']($_POST['subject']) > [glow=red,2,300]200[/glow])
      $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, [glow=red,2,300]200[/glow]);