Tento jednoduchý plugin by mal pomôcť všetkým, ktorý sa rozhodli prejsť na bbPress a pritom sa snažia o migráciu z iného riešenia.

Nie som autorom pluginu, ale rozhodol som sa prípadnych záujemcov poistiť: http://www.simonwheatley.co.uk/2009/07/03/migration-to-bbpress-fix-topic-slugs/ Migrácia z phpBB bola hotovým utrpením, a funkčné SEO odkazy boli pre mňa zásadným faktorom. A keďže som chcel v čo najmenšom možnom množstve eliminovať stratu údajov, museli začať hodiny záloh a úprav v DB. Vopred upozrňujem, že prechod z iného riešenia (u mňa phpBB) može byť utrpením o to viac, ak sa snažíte o integráciu s WordPressom. Mňa zachránilo hľadanie a nájdenie pluginu…

Autorom pluginu je simonwheatley, ktorému týmto ďakujem. ( Thanks man! )

Tu pre záujemcov, ktorý sa dostali až sem poskytujem náprava vo forme pluginu. Postup je jednoduchý:

  1. Vytvoriť súbor s ľubovolným názvom v priečinku my-plugins
  2. Skopírovať php kód, ktorý je uvedený nižšie do vytvoreného súboru
  3. uložiť
  4. aktivovať plugin Creatre Slugs
  5. Vymazať vami vytovrený súbor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
Plugin Name: Create Slugs
Description: Creates topic and forum slugs where previously there weren't any. Outputs into error log, only works on plugin activation.
Plugin URI: http://simonwheatley.co.uk/bbpress/create-slugs
Author: simonwheatley
Author URI: http://simonwheatley.co.uk
Version: 1.1
*/
class CreateSlugs
{
protected $topics_have_slugs;
protected $forums_have_slugs;
function __construct()
{
global $bbdb;
$this->db = & $bbdb;
$this->topics_have_slugs = false;
$this->forums_have_slugs = false;
}
public function create_slugs()
{
$this->create_topic_slugs();
if ( ! $this->topics_have_slugs ) return;
$this->create_forum_slugs();
if ( ! $this->forums_have_slugs ) return;
// Finished!
echo "Everything now has slugs, you can disable the create topic slugs plugin by removing it from the plugins directory.";
exit;
}
protected function maybe_finished()
{
// if ( ! $this->forums_have_slugs ) return;
}
protected function create_topic_slugs()
{
error_log( "TOPICS" );
$topics = $this->slugless( 'topics' );
if ( ! count( $topics ) ) $this->topics_have_slugs = true;
foreach( $topics AS $topic ) {
$new_slug = $this->generate_slug( 'topic', $topic->topic_id, $topic->topic_title );
$this->update_topic_slug( $topic->topic_id, $new_slug );
error_log( "$new_slug >> $topic->topic_title" );
}
error_log( "Last Query: " . $this->db->last_query );
}
protected function create_forum_slugs()
{
error_log( "FORUMS" );
$forums = $this->slugless( 'forums' );
if ( ! count( $forums ) ) $this->forums_have_slugs = true;
foreach( $forums AS $forum ) {
$new_slug = $this->generate_slug( 'forum', $forum->forum_id, $forum->forum_name );
$this->update_forum_slug( $forum->forum_id, $new_slug );
error_log( "$new_slug >> $forum->forum_name" );
}
}
protected function slugless( $type )
{
// Just do 1,000 at a time for now
if ( $type == 'topics' ) {
$topics_table = $this->db->topics;
$sql = " SELECT topic_id, topic_title FROM $topics_table WHERE topic_slug IS NULL OR topic_slug = '' LIMIT 1000 ";
}
if ( $type == 'forums' ) {
$forums_table = $this->db->forums;
$sql = " SELECT forum_id, forum_name FROM $forums_table WHERE forum_slug IS NULL OR forum_slug = '' LIMIT 1000 ";
}
// No need to prepared the SQL, no user input
return $this->db->get_results( $sql );
}
protected function generate_slug( $type, $id, $title )
{
$slug = $_slug = bb_slug_sanitize( wp_specialchars_decode( $title, ENT_QUOTES ) );
if ( strlen( $_slug ) < 1 ) $slug = $_slug = '0';
// Ensure the slug is unique
while ( is_numeric( $slug ) || $existing_slug = $this->existing_slug( $type, $id, $slug ) ) {
$slug = bb_slug_increment( $_slug, $existing_slug );
}
return $slug;
}
protected function existing_slug( $type, $id, $slug )
{
if ( $type == 'topic' ) {
$table = $this->db->topics;
$sql = "SELECT topic_slug FROM $table WHERE topic_slug = %s AND topic_id != %d";
}
if ( $type == 'forum' ) {
$table = $this->db->forums;
$sql = "SELECT forum_slug FROM $table WHERE forum_slug = %s AND forum_id != %d";
}
$prepared_sql = $this->db->prepare( $sql, $slug, $id );
return $this->db->get_var( $prepared_sql );
}
protected function update_topic_slug( $topic_id, $topic_slug )
{
$table = $this->db->topics;
$data = array( 'topic_slug' => $topic_slug );
$where = array( 'topic_id' => $topic_id );
$this->db->update( $table, $data, $where );
}
protected function update_forum_slug( $forum_id, $forum_slug )
{
$table = $this->db->forums;
$data = array( 'forum_slug' => $forum_slug );
$where = array( 'forum_id' => $forum_id );
$this->db->update( $table, $data, $where );
}
}
$create_slugs = new CreateSlugs();
add_action( 'bb_init', array( & $create_slugs, 'create_slugs' ) );
?>