Во первых, без знаний php+mysql в эту тему лезть не надо было.
Во вторых. то, что вы увидите ниже это всего лишь наработки, а не полноценная реализация. Они создавались с одной целью, посмотреть смогу ли я реализовать эту довольно не простую функцию.
В третьих. Для полноценной реализации ЧПУ код должен дороьатывать конечный пользователь.
В последних. Стабильная работа мода не гарантируеться, и он нуждаеться в доработке.
MySQL:
Код: Выделить всё
CREATE TABLE phpbb_humanoid_topics
(
topic_id SMALLINT(8),
topic_humanoid_name VARCHAR(150),
topic_is_current_name TINYINT(1),
humanoid_name_used_count SMALLINT(5)
);
Код: Выделить всё
RewriteEngine on
RewriteRule topics-(.*).html viewtopic.php\?name=$1
Код: Выделить всё
#
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
#
$subject = ( !empty($HTTP_POST_VARS['subject']) ) ? trim($HTTP_POST_VARS['subject']) : '';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$subject_hum = str_to_humans($subject);
#
#-----[ FIND ]------------------------------------------
#
submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
#
#-----[ IN-LINE, FIND ]------------------------------------------
#
str_replace("\'", "''", $subject)
#
#-----[ IN-LINE, AFTER ADD ]------------------------------------------
#
, $subject_hum
#
#-----[ OPEN ]------------------------------------------
#
viewforum.php
#
#-----[ FIND ]------------------------------------------
#
//
// All announcement data, this keeps announcements
// on each viewforum page ...
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_poster = u.user_id
AND p.post_id = t.topic_last_post_id
AND p.poster_id = u2.user_id
AND t.topic_type = " . POST_ANNOUNCE . "
ORDER BY t.topic_last_post_id DESC ";
#
#-----[ REPLACE WITH ]------------------------------------------
#
//
// All announcement data, this keeps announcements
// on each viewforum page ...
//
$sql = "SELECT t.*, h.topic_humanoid_name, h.humanoid_name_used_count, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
FROM " . TOPICS_TABLE . " t, phpbb_humanoid_topics h, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND h.topic_id = t.topic_id
AND h.topic_is_current_name = 1
AND t.topic_poster = u.user_id
AND p.post_id = t.topic_last_post_id
AND p.poster_id = u2.user_id
AND t.topic_type = " . POST_ANNOUNCE . "
#
#-----[ FIND ]------------------------------------------
#
//
// Grab all the basic data (all topics except announcements)
// for this forum
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_poster = u.user_id
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND u2.user_id = p2.poster_id
AND t.topic_type <> " . POST_ANNOUNCE . "
$limit_topics_time
ORDER BY t.topic_type DESC, t.topic_last_post_id DESC, t.topic_last_post_id DESC
LIMIT $start, ".$board_config['topics_per_page'];
#
#-----[ REPLACE WITH ]------------------------------------------
#
//
// Grab all the basic data (all topics except announcements)
// for this forum
//
$sql = "SELECT t.*, h.topic_humanoid_name, h.humanoid_name_used_count, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
FROM " . TOPICS_TABLE . " t, phpbb_humanoid_topics h, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND h.topic_id = t.topic_id
AND h.topic_is_current_name = 1
AND t.topic_poster = u.user_id
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND u2.user_id = p2.poster_id
AND t.topic_type <> " . POST_ANNOUNCE . "
$limit_topics_time
ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
LIMIT $start, ".$board_config['topics_per_page'];
#
#-----[ FIND ]------------------------------------------
#
$topic_id = $topic_rowset[$i]['topic_id'];
#
#-----[ AFTER, ADD ]------------------------------------------
#
$topic_name = ( $topic_rowset[$i]['humanoid_name_used_count'] ) ? ($topic_rowset[$i]['topic_humanoid_name'] . '-' . $topic_rowset[$i]['humanoid_name_used_count']) : $topic_rowset[$i]['topic_humanoid_name'];
#
#-----[ FIND ]------------------------------------------
#
$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
#
#-----[ REPLACE WITH ]------------------------------------------
#
$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?name=$topic_name&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
#
#-----[ FIND ]------------------------------------------
#
$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
#
#-----[ REPLACE WITH ]------------------------------------------
#
$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?name=$topic_name&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
#
#-----[ FIND ]------------------------------------------
#
$goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '">' . $times . '</a>';
#
#-----[ REPLACE WITH ]------------------------------------------
#
$goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?name=$topic_name&start=$j") . '">' . $times . '</a>';
#
#-----[ FIND ]------------------------------------------
#
$view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
#
#-----[ REPLACE WITH ]------------------------------------------
#
$view_topic_url = append_sid("viewtopic.$phpEx?name=$topic_name");
#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
if ( isset($HTTP_GET_VARS[POST_POST_URL]))
{
$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( isset($HTTP_GET_VARS['name']) )
{
$topic_name = strtolower($HTTP_GET_VARS['name']);
$count = intval(substr(strrchr($topic_name, '-'), 1));
$topic_name = ( $pos = strrpos($topic_name, '-') ) ? substr($topic_name, 0, $pos) : $topic_name;
$sql = "SELECT topic_id from phpbb_humanoid_topics " .
"WHERE topic_humanoid_name = '$topic_name' AND humanoid_name_used_count = $count";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain humanoid information', '', __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
$topic_id = $row['topic_id'];
}
}
else
{
$topic_name = '';
$count = 0;
}
#
#-----[ FIND ]------------------------------------------
#
if ( !isset($topic_id) && !isset($post_id) )
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ( !isset($topic_name) && !isset($topic_id) && !isset($post_id) )
#
#-----[ OPEN ]------------------------------------------
#
/includes/functions_post.php
#
#-----[ FIND ]------------------------------------------
#
function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, &$bbcode_uid, &$post_username, &$post_subject, &$post_message, &$poll_title, &$poll_options, &$poll_length)
#
#-----[ IN-LINE, FIND ]------------------------------------------
#
&$post_subject
#
#-----[ IN-LINE, AFTER ADD ]------------------------------------------
#
, &$human_subj
#
#-----[ FIND ]------------------------------------------
#
if ($mode == 'newtopic')
{
$topic_id = $db->sql_nextid();
#
#-----[ AFTER, ADD ]------------------------------------------
#
$is_current = 1;
}
else
{
$sql = "SELECT topic_humanoid_name FROM phpbb_humanoid_topics " .
"WHERE topic_id = $topic_id AND topic_is_current_name = 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain humanoid information', '', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result))
{
$is_current = ( $row['topic_humanoid_name'] != $human_subj ) ? 1 : 0;
if ($is_current)
{
$sql = "UPDATE phpbb_humanoid_topics SET topic_is_current_name = 0 " .
"WHERE topic_id = $topic_id AND topic_is_current_name = 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not update humanoid information', '', __LINE__, __FILE__, $sql);
}
}
}
}
if ($is_current)
{
$sql = "SELECT humanoid_name_used_count FROM phpbb_humanoid_topics " .
"WHERE topic_humanoid_name = '$human_subj' " .
"ORDER BY humanoid_name_used_count DESC LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain humanoid information', '', __LINE__, __FILE__, $sql);
}
$used_count = ($row = $db->sql_fetchrow($result)) ? ($row['humanoid_name_used_count'] + 1) : 0;
$sql = "INSERT INTO phpbb_humanoid_topics " .
"(topic_id, topic_humanoid_name, topic_is_current_name, humanoid_name_used_count) VALUES " .
"($topic_id, '$human_subj', $is_current, $used_count)";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain humanoid information', '', __LINE__, __FILE__, $sql);
}
#
#-----[ OPEN ]------------------------------------------
#
/includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
// added at phpBB 2.0.11 to properly format the username
function phpbb_clean_username($username)
#
#-----[ BEFORE, ADD ]------------------------------------------
#
function str_to_humans($str)
{
if (trim($str) == '' || trim($str, '_') == '')
{
return 'empty';
}
else
{
$str = preg_replace('#[\s\-]#', '_', strtolower(trim($str)));
$srt = preg_replace('#_{1,}#', '_', preg_replace('#\W#', '', $str));
$str = trim($str, '_');
return $str;
}
}
Ах, и ещё. Ставить надо только на чистый 2.0.15
Добавлено спустя 31 минуту 48 секунд:
Немного опшу переменные в sql-запросе.
topic_id - тема, для которой предназначаеться даный ЧПУ
topic_humanoid_name - имя которое будет использовать пользователь, чтобы попасть в тему.php
topic_is_current_name - определяет, какой из названий темы будет выводиться при просмотре viewforum
humanoid_name_used_count - служит для обозначения порядкового номера имя ЧПУ.
Немного попродробнее о последних двух.
Ситуация 1. Допустим пользователь назвал тему по старой привычке "Обсуждение phpBB 2.0.15", а потом вспомнил, что на дворе-то не 2.0.15 а 3.0.0. И исправил название темы на "Обсуждение phpBB 3.0.0".
Соответственно и ЧПУ ссылка тоже изменилась. И нам надо показывать не старую с версией 2.0.15, а новую 3.0.0. А так как старые ЧПУ не удаляються (на них уже сослалось пол интернета), то мы устанавливаем флажок с названием topic_is_current_name, что теперь всем надо выдавать ЧПУ не с версией 2.0.15, а с версией 3.0.0
Ситуция 2.
Вася Пуповкин решил поставить форум, но у него с завидной постоянностью выскакивает ошибка "Please delete install/ and contrib/ directories". Он решил создать тему, и назвал её в честь этой ошибки. ЧПУ получило имя "please_delete_install_and_contrib_directories". Но тут через два часа с такой же проблемой сталкнулся Вася Пупапоповкин. И так же решил создать тему и назвать её в честь ошибки критичиской. И тут у нас получаеться что две разные темы имеют один и тот же ЧПУ. Не порядок, подумал я и дабавил поле humanoid_name_used_count что бы знать сколько раз использовался данный ЧПУ и если испольховался добавить единичку сверху. И стала ссылка посылать в тему Пупапоповкина не на "please_delete_install_and_contrib_directories", а на "please_delete_install_and_contrib_directories-1". Соответсвенно ссылка для следуещего родственника Василия будет "please_delete_install_and_contrib_directories-2".
Описал как мог.