ผู้เขียน หัวข้อ: เพิ่มปุ่มจัดการกระทู้ปักหมุด  (อ่าน 1030 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ smf

  • [color=green][i]"ถ้าคุณไม่สามารถอธิบายอย่างง่ายๆ ให้คนอื่นเข้าใจได้แล้วล่ะก็ แสดงว่าคุณยังเข้าใจมันไม่ดีพอ"[/i][/color]
  • Administrator
  • Hero Member
  • *****
  • กระทู้: 1,368
  • พอยท์: 5
    • ดูรายละเอียด
    • pordoo.com
    • อีเมล์
เพิ่มปุ่มจัดการกระทู้ปักหมุด
« เมื่อ: 4 ตุลาคม 2015, 00:05:34 »
Mod Name:Order Stickied Topics
http://custom.simplemachines.org/mods/index.php?mod=1321








File Edits

./index.php
Find:
โค๊ด: [Select]
'pm' => array('PersonalMessage.php', 'MessageMain'),Replace With:
โค๊ด: [Select]
'pm' => array('PersonalMessage.php', 'MessageMain'),
// The action for the Order Stickied Topics Mod.
'orderstickiedtopics' => array('Post.php', 'OrderStickiedTopics'),


./Sources/Post.php
Find:
โค๊ด: [Select]
// So you wanna (un)sticky this...let's see.
if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || $_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
unset($_POST['sticky']);
Replace With:
โค๊ด: [Select]
// So you wanna (un)sticky this...let's see.
if (isset($_POST['sticky']) && (empty($modSettings['enableStickyTopics']) || (empty($_POST['sticky']) == empty($topic_info['is_sticky'])) || !allowedTo('make_sticky')))
unset($_POST['sticky']);


Find:
โค๊ด: [Select]
// Change the sticky status of this topic?
if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
unset($_POST['sticky']);
Replace With:
โค๊ด: [Select]
// Change the sticky status of this topic?
if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || (empty($_POST['sticky']) == empty($topic_info['is_sticky']))))
unset($_POST['sticky']);

Find:
โค๊ด: [Select]
// Assume the first message if no message ID was given.
$request = $smcFunc['db_query']('', '
SELECT
t.locked, t.num_replies, t.id_member_started, t.id_first_msg,
Replace With:
โค๊ด: [Select]
// Assume the first message if no message ID was given.
$request = $smcFunc['db_query']('', '
SELECT
t.locked, t.num_replies, t.id_member_started, t.id_first_msg, t.is_sticky,

Find:
โค๊ด: [Select]
'board' => $board,
'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null,
'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null,
Replace With:
โค๊ด: [Select]
'board' => $board,
'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null,
'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) && !(empty($_POST['sticky']) == empty($row['is_sticky'])) ? (int) $_POST['sticky'] : null,

Find:
โค๊ด: [Select]
?>Add Before:
โค๊ด: [Select]
// Function for the Order Stickied Topics Action.
function OrderStickiedTopics()
{
global $board, $smcFunc, $board_info, $modSettings, $context, $txt, $topic;

// Make sure that we have a valid board.
if(empty($board))
redirectexit();

// Make sure that the user is allowed to sticky topics. And that we are using stickied topics.
if(!allowedTo('make_sticky') || empty($modSettings['enableStickyTopics']))
redirectexit('board='.$board.'.0');

// Do we have a topic id?
if(!empty($topic))
{
// First get some information about this topic.
$result = $smcFunc['db_query']('', '
SELECT is_sticky
FROM {db_prefix}topics
WHERE id_topic = {int:topic_id}
AND id_board = {int:board_id}',
array(
'board_id' => $board,
'topic_id' => $topic,
)
);

// Make sure that we got some valid topic information.
if(!($data = $smcFunc['db_fetch_assoc']($result)))
redirectexit('action=orderstickiedtopics;board='.$board.'.0');

$smcFunc['db_free_result']($result);

// Make sure that we aren't about to unsticky this topic, and that its a sticky.
if(($data['is_sticky'] == 0)
|| (($data['is_sticky'] == 1) && isset($_GET['decrease'])))
redirectexit('action=orderstickiedtopics;board='.$board.'.0;');

// Get a correct value to set for the 'stickyness' of this topic. :D
if(isset($_GET['unsticky']))
$value = '0';
// Increment?
elseif(isset($_GET['increment']))
$value = "is_sticky + 1";
// Decrease?
elseif(isset($_GET['decrease']))
$value = "is_sticky - 1";
// If we have no valid value, then we can't do anything. :(
else
redirectexit('action=orderstickiedtopics;board='.$board.'.0');

// Update the topic.
$smcFunc['db_query']('','
UPDATE {db_prefix}topics
SET is_sticky = {raw:value}
WHERE id_topic = {int:topic_id}',
array(
'topic_id' => $topic,
'value' => $value,
)
);

// Finally redirect us back to the order stickied topics page for this topics board.
redirectexit('action=orderstickiedtopics;board='.$board.'.0;');
}

// Get a list of Stickied Topics for this board.
$result = $smcFunc['db_query']('','
SELECT t.id_topic, t.is_sticky, m.subject
FROM ({db_prefix}topics as t)
LEFT JOIN {db_prefix}messages as m on (m.id_msg = t.id_first_msg)
WHERE is_sticky != 0
AND t.id_board = {int:board_id}
ORDER BY t.is_sticky DESC, t.id_last_msg DESC',
array(
'board_id' => $board,
)
);

// Setup the topic list for the template.
$context['topics'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$context['topics'][] = array(
'id' => $row['id_topic'],
'value' => $row['is_sticky'],
'title' => $row['subject'],
);
}
$smcFunc['db_free_result']($result);

// Finally set up some necessary *stuff* for the template.
loadTemplate('Post');
$context['sub_template'] = 'orderstickiedtopics';
$context['page_title'] = $board_info['name'];
}


./Sources/MessageIndex.php
Find:
โค๊ด: [Select]
$context['can_post_poll'] = $modSettings['pollMode'] == '1' && allowedTo('poll_post') && $context['can_post_new'];Add After:
โค๊ด: [Select]
// Add the 'can_order_stickied_topics' permission, for the Order Stickied Topics mod.
$context['can_order_stickied_topics'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);


./Themes/default/MessageIndex.template.php
Find:
โค๊ด: [Select]
'post_poll' => array('test' => 'can_post_poll', 'text' => 'new_poll', 'image' => 'new_poll.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'),
Replace With:
โค๊ด: [Select]
'post_poll' => array('test' => 'can_post_poll', 'text' => 'new_poll', 'image' => 'new_poll.gif', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'),
// Show the Link/Button for the Order Stickied Topics Mod.
'order_stickied_topics' => array('test' => 'can_order_stickied_topics', 'text' => 'OrderStickiedTopics_title', 'lang' => true, 'url' => $scripturl . '?action=orderstickiedtopics;board=' . $context['current_board'] . '.0'),


./Themes/default/Post.template.php
Find:
โค๊ด: [Select]
?>Add Before:
โค๊ด: [Select]
// Function to display the list of stickiedtopics.
function template_orderstickiedtopics()
{
global $context, $txt, $board_info, $scripturl, $settings;

// Show the start of the table, as well as the main heading and the column headings.
echo '
<br />
<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="60%">
<tr class="catbg3">
<td colspan="5" align="left">
<div style="float: left;">
<b>', $txt['OrderStickiedTopics_title'] ,'</b> - <a href="' . $scripturl . '?board=', $context['current_board'], '.0">', $board_info['name'], '</a>
</div>
</td>
</tr>
<tr class="titlebg">
<th>', $txt['subject'], '</th>
<th>', $txt['OrderStickiedTopics_current'], '</th>
<th>', $txt['OrderStickiedTopics_modify'], '</th>
</tr>';

// Show a list of the topics.
foreach($context['topics'] as $topic)
{
echo '
<tr>
<td align="left" valign="top" class="windowbg"><b><a href="', $scripturl, '?topic=', $topic['id'], '.0">', $topic['title'], '</a></b></td>
<td align="left" valign="top" class="windowbg2" style="text-align:center;">', $topic['value'], '</td>
<td align="center" valign="top" class="windowbg2">
<a href="', $scripturl, '?action=orderstickiedtopics;topic=', $topic['id'],';decrease"><img src="', $settings['images_url'], '/sort_down.gif" alt="', $txt['OrderStickiedTopics_decrease'], '" border="0" /></a>
<a href="', $scripturl, '?action=orderstickiedtopics;topic=', $topic['id'],';increment"><img src="', $settings['images_url'], '/sort_up.gif" alt="', $txt['OrderStickiedTopics_increase'], '" border="0" /></a>
&nbsp;&nbsp;&nbsp;<a href="', $scripturl, '?action=orderstickiedtopics;topic=', $topic['id'],';unsticky">', $txt['OrderStickiedTopics_unsticky'], '</a>
</td>
</tr>';
}

// If we have no topics, then show a short message telling the moderator.
if(empty($context['topics']))
echo '
<tr>
<td colspan="3" valign="top" class="windowbg">', $txt['OrderStickiedTopics_emptylist'], '</td>
</tr>';

// Finish the table.
echo '
<tr class="catbg3">
<td colspan="5" align="left">
<b style="font-size:14px;"><a href="', $scripturl, '?board=', $context['current_board'], '.0">', $txt['OrderStickiedTopics_back'], ' ', $board_info['name'], '</a></b>
</td>
</tr>
</table>';
}


./Themes/default/languages/Modifications.english.php
Find :
โค๊ด: [Select]
?>Add Before:
โค๊ด: [Select]
// Text for the Order Stickied Topics Mod.
$txt['OrderStickiedTopics_title'] = 'Order Stickied Topics';
$txt['OrderStickiedTopics_current'] = 'Current \'Sticky\' Value';
$txt['OrderStickiedTopics_back'] = 'Back To';
$txt['OrderStickiedTopics_modify'] = 'Modify Sticky Value';
$txt['OrderStickiedTopics_unsticky'] = 'Un-Sticky';
$txt['OrderStickiedTopics_increase'] = 'Increase';
$txt['OrderStickiedTopics_decrease'] = 'Decrease';
$txt['OrderStickiedTopics_emptylist'] = 'This board currently has no stickied topics.';

« แก้ไขครั้งสุดท้าย: 4 ตุลาคม 2015, 00:25:50 โดย pordoo »