รายละเอียด ปกติไฟล์แนบของ SMF จะแสดงบริเวณล่างสุดของกระทู้โดยมีเส้นคั่น และแสดงเป็นรูปขนาดย่อหากต้องการรูปเต็มขนาดก็ต้องคลิกอีกทีหนึ่ง ทำให้ไม่สะดวกในการใช้รูปประข้อความ หรือบทความเพราะว่ารูปกับข้อความอยู่คนละตำแหน่งกัน mod นี้จะช่วยให้การแสดงไฟล์แนบอยู่แนวเดียวกับข้อความ เช่น ขณะผู้เขียนกำลังพิมพ์คำอธิบาย mod นี้อยู่และต้องการแสดงรูปประกอบก็สามารถทำได้เลยโดยการแทรกแบบนี้ [attachment=1] รูปไฟล์แนบก็จะอยู่ในตำแหน่งที่แทรก ซึ่งการแทรกก็ทำได้อย่างง่ายๆ แค่คลิกเดียว ดังรูปตัวอย่าง
ตัวอย่าง
แก้ไขไฟล์:file $sourcedir/Display.php
ค้นหา -->>
if (empty($options['view_newest_first']))
$counter++;
เพิ่มไว้ก่อน -->>
// Attachment Positioniong Mod: Start
if (empty($modSettings['attachmentEnable']) || !allowedTo('view_attachments')) {
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
$output['body'] = preg_replace($pattern, $txt['attachment_nopermission'], $output['body']);
} else {
// GRACEFULLY REPLACE ATTACHMENTS INSIDE QUOTES OR CODE TAGS WITH THE TEXT STRING [ ATTACHMENT ]
// WE MAY NEED TO DO THIS FOR POSTS *WITHOUT* ANY ATTACHMENTS
if(preg_match_all('#<div class="(code|quote)">(.*?)</div>#im'. ($context['utf8'] ? 'u' : ''), $output['body'], $quotecode, PREG_PATTERN_ORDER)) {
$quotecode = array_unique($quotecode[0]);
// GO THROUGH EACH QUOTE/CODE ELEMENT
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
foreach ($quotecode as $a => $b) {
$c = $b;
$c = preg_replace($pattern, $txt['attachment'], $c);
$output['body'] = str_replace($b, $c, $output['body']);
}
unset($a,$b,$c,$quotecode,$pattern);
}
// HOW MANY ATTACHMENTS ARE THERE?
$z = count($output['attachment']);
// NO ATTACHMENTS, SO WE CAN AVOID THIS PART
if ($z != 0) {
// NOW REPLACE OUR ATTACHMENT BBCODE WITH THE ATTACHMENTS
for($i=0;$i<$z;$i++) {
$attachment = $output['attachment'][$i];
if(strpos($output['body'],'[attachment='.($i+1).']') !== FALSE) {
$replace = '<div class="smalltext">';
if ($attachment['is_image']) {
// Don't display image attachments that use the bbcode twice
$context['dontshowattachment'][$i+1] = $attachment['id'];
if ($attachment['thumbnail']['has_thumb']) {
$replace .= '
<a href="'. $attachment['href']. ';image" id="link_'. $attachment['id']. '" onclick="'. $attachment['thumbnail']['javascript'] .'"><img src="'. $attachment['thumbnail']['href']. '" alt="" id="thumb_'. $attachment['id']. '" border="0" /></a><br />';
} else {
$replace .= '
<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" border="0" /><br />';
}
}
$replace .= '<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" /> ' . $attachment['name'] . '</a> ('. $attachment['size']. ($attachment['is_image'] ? '. ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)</div>';
$output['body'] = str_replace('[attachment='.($i+1).']',$replace, $output['body']);
}
unset($replace);
}
}
// GRACEFULLY REPLACE BBCODE FOR ANY INVALID/MISSING/DELETED ATTACHMENTS WITH ERROR TEXT STRING
$pattern = '#\[attachment=([0-9a-z\#\-_ ]{1,10})\]#i'.($context['utf8'] ? 'u' : '') ;
$output['body'] = preg_replace($pattern, $txt['attachment_invalid'], $output['body']);
}
// Attachment Positioniong Mod: End
file $sourcedir/Post.php
ค้นหา -->>
$context['message']['body'] = parse_bbc($context['message']['body'], $row['smileysEnabled'], $row['ID_MSG']);
เพิ่มไว้หลัง -->>
// Attachment Positioniong Mod: Start
// FETCH ATTACHMENTS IF ENABLED AND ALLOWED TO VIEW ATTACHMENTS
if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments')) {
// GRACEFULLY REPLACE ATTACHMENTS INSIDE QUOTES OR CODE TAGS WITH THE TEXT STRING [ ATTACHMENT ]
// WE MAY NEED TO DO THIS FOR POSTS *WITHOUT* ANY ATTACHMENTS
if(preg_match_all('#<div class="(code|quote)">(.*?)</div>#im'. ($context['utf8'] ? 'u' : ''), $context['message']['body'], $quotecode, PREG_PATTERN_ORDER)) {
$quotecode = array_unique($quotecode[0]);
// GO THROUGH EACH QUOTE/CODE ELEMENT
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
foreach ($quotecode as $a => $b) {
$c = $b;
$c = preg_replace($pattern, $txt['attachment'], $c);
$context['message']['body'] = str_replace($b, $c, $context['message']['body']);
}
unset($a,$b,$c,$quotecode,$pattern);
}
// WE NEED ACCESS TO THE GLOBALS
global $settings, $attachments;
// QUERY TO PULL THE ATTACHMENTS - MODIFIED SLIGHTLY FROM DISPLAY.PHP CODE
$attachments = array();
$request = db_query("
SELECT
a.ID_ATTACH, a.ID_MSG, a.filename, IFNULL(a.size, 0) AS filesize, a.downloads,
a.width, a.height" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ",
IFNULL(thumb.ID_ATTACH, 0) AS ID_THUMB, thumb.width AS thumb_width, thumb.height AS thumb_height") . "
FROM {$db_prefix}attachments AS a" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : "
LEFT JOIN {$db_prefix}attachments AS thumb ON (thumb.ID_ATTACH = a.ID_THUMB)") . "
WHERE a.ID_MSG = ".$row['ID_MSG']."
AND a.attachmentType = 0", __FILE__, __LINE__);
$temp = array();
$z = mysql_num_rows($request);
// ONLY CONTINUE IF WE HAVE ATTACHMENTS
if ($z != 0) {
while ($temprow = mysql_fetch_assoc($request)) {
$temp[$temprow['ID_ATTACH']] = $temprow;
if (!isset($attachments[$temprow['ID_MSG']])) {
$attachments[$temprow['ID_MSG']] = array();
}
}
mysql_free_result($request);
// NOW SORT
ksort($temp);
// NOW PUT INTO THE ATTACHMENTS ARRAY
foreach ($temp as $temprow) {
$attachments[$temprow['ID_MSG']][] = $temprow;
}
// TIDY UP
unset($temp,$temprow);
// REQUIRE FUNCTION FROM THAT FILE
require_once($sourcedir . '/Display.php');
// HERE WE TRY TO USE IDENTICAL VARS AS USED BY DISPLAY.PHP TO MAKE IT EASIER
$output = array();
$output['attachment'] = loadAttachmentContext($row['ID_MSG']);
// NOW REPLACE OUR ATTACHMENT BBCODE WITH THE ATTACHMENTS
for($i=0;$i<$z;$i++) {
$attachment = $output['attachment'][$i];
if(strpos($context['message']['body'],'[attachment='.($i+1).']') !== FALSE) {
$replace = '<div class="smalltext">';
if ($attachment['is_image']) {
if ($attachment['thumbnail']['has_thumb']) {
$replace .= '
<a href="'. $attachment['href']. ';image" id="link_'. $attachment['id']. '" onclick="'. $attachment['thumbnail']['javascript'] .'"><img src="'. $attachment['thumbnail']['href']. '" alt="" id="thumb_'. $attachment['id']. '" border="0" /></a><br />';
} else {
$replace .= '
<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" border="0" /><br />';
}
}
$replace .= '<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" /> ' . $attachment['name'] . '</a> ('. $attachment['size']. ($attachment['is_image'] ? '. ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)</div>';
$context['message']['body'] = str_replace('[attachment='.($i+1).']',$replace, $context['message']['body']);
}
unset($replace);
}
}
// GRACEFULLY REPLACE BBCODE FOR ANY INVALID/MISSING/DELETED ATTACHMENTS WITH ERROR TEXT STRING
$pattern = '#\[attachment=([0-9a-z\#\-_ ]{1,10})\]#i'.($context['utf8'] ? 'u' : '') ;
$context['message']['body'] = preg_replace($pattern, $txt['attachment_invalid'], $context['message']['body']);
}
// Attachment Positioniong Mod: End
ค้นหา -->>
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
เพิ่มไว้หลัง -->>
// SHOW ATTACHMENT TEXT STRING OR ERROR TEXT STRING IN TOPIC HISTORY
global $txt;
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
if (empty($modSettings['attachmentEnable']) || !allowedTo('view_attachments')) {
$row['body'] = preg_replace($pattern, $txt['attachment_nopermission'], $row['body']);
} else {
$row['body'] = preg_replace($pattern, $txt['attachment'], $row['body']);
}
ค้นหา -->>
$context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1);
เพิ่มไว้หลัง -->>
// SHOW ATTACHMENT TEXT STRING OR ERROR TEXT STRING IN TOPIC HISTORY
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
if (empty($modSettings['attachmentEnable']) || !allowedTo('view_attachments')) {
$context['preview_message'] = preg_replace($pattern, $txt['attachment_nopermission'], $context['preview_message']);
} else {
$context['preview_message'] = preg_replace($pattern, $txt['attachment'], $context['preview_message']);
}
file $sourcedir/Recent.php
ค้นหา -->>
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
เพิ่มไว้หลัง -->>
// SHOW ATTACHMENT TEXT STRING OR ERROR TEXT STRING IN TOPIC HISTORY
$pattern = '#\[attachment=([0-9])\]#i'.($context['utf8'] ? 'u' : '') ;
if (empty($modSettings['attachmentEnable']) || !allowedTo('view_attachments')) {
$row['body'] = preg_replace($pattern, $txt['attachment_nopermission'], $row['body']);
} else {
$row['body'] = preg_replace($pattern, $txt['attachment'], $row['body']);
}
file $themedir/Display.template.php
ค้นหา -->>
foreach ($message['attachment'] as $attachment)
แก้เป็น -->>
$i = 0;
foreach ($message['attachment'] as $attachment)
ค้นหา -->>
if ($attachment['is_image'])
แก้เป็น -->>
if (empty($context['dontshowattachment'][$i+1])) $context['dontshowattachment'][$i+1] = "";
if ($attachment['is_image'] && $context['dontshowattachment'][$i+1] !== $attachment['id'])
ค้นหา -->>
echo '
<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" /> ' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
แก้เป็น -->>
if ($context['dontshowattachment'][$i+1] !== $attachment['id'])
echo '
<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" /> ' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
$i++;
file $themedir/Post.template.php
ค้นหา -->>
foreach ($context['current_attachments'] as $attachment)
echo '
<input type="checkbox" name="attach_del[]" value="', $attachment['id'], '"', empty($attachment['unchecked']) ? ' checked="checked"' : '', ' class="check" /> ', $attachment['name'], '<br />';
แก้เป็น -->>
foreach ($context['current_attachments'] as $attid => $attachment)
echo '
<input type="checkbox" name="attach_del[]" value="', $attachment['id'], '"', empty($attachment['unchecked']) ? ' checked="checked"' : '', ' class="check" /> ', $attachment['name'], ' <a href="javascript:void(0);" onclick="replaceText(\'[attachment=',($attid+1),']\', document.forms.', $context['post_form'], '.', $context['post_box_name'], '); return false;">[', $txt['attachment_insert'] ,' ', ($attid+1),']</a><br />';
ค้นหา -->>
<input type="file" size="48" name="attachment[]" />';
แก้เป็น -->>
<input type="file" size="48" name="attachment[]" /> <a href="javascript:void(0);" onclick="replaceText(\'[attachment=', (count($context['current_attachments']) + 1) ,']\', document.forms.', $context['post_form'], '.', $context['post_box_name'], '); return false;">[', $txt['attachment_insert'] ,' ', (count($context['current_attachments']) + 1) ,']</a>';
ค้นหา -->>
function addAttachment()
{
if (allowed_attachments <= 0)
return alert("', $txt['more_attachments_error'], '");
setOuterHTML(document.getElementById("moreAttachments"), \'<br /><input type="file" size="48" name="attachment[]" /><span id="moreAttachments"></span>\');
allowed_attachments = allowed_attachments - 1;
return true;
}
แก้เป็น -->>
var count_attachments = ', count($context['current_attachments']) ,' + 1;
function addAttachment()
{
if (allowed_attachments <= 0)
return alert("', $txt['more_attachments_error'], '");
count_attachments = count_attachments + 1 ;
setOuterHTML(document.getElementById("moreAttachments"), \'<br /><input type="file" size="48" name="attachment[]" /> <a href="javascript:void(0);" onclick="replaceText(\\\'[attachment=\'+ count_attachments +\']\\\', document.forms.', $context['post_form'], '.', $context['post_box_name'], '); return false;">[', $txt['attachment_insert'] ,' \'+ count_attachments +\']</a> <span id="moreAttachments"></span>\');
allowed_attachments = allowed_attachments - 1;
return true;
}
file $themedir/languages/Modifications.thai-utf8.php
เพิ่ม -->>
$txt['attachment'] = ' [ ไพล์แนบ ] ';
$txt['attachment_nopermission'] = ' [ ไพล์แนบ: คุณไม่ได้รับอนุญาตให้ดูไฟล์แนบ ] ';
$txt['attachment_invalid'] = ' [ ไฟล์แนบไม่ถูกต้อง หรือไม่มีอยู่ ] ';
$txt['attachment_disabled'] = ' [ ไฟล์แนบไม่ได้เปิดใช้งาน ] ';
$txt['attachment_insert'] = 'แทรกไฟล์แนบ';
วิธีใช้:
ลิงค์หัวข้อ:
http://dexmore.com/topic/5735