Revision history for WikkaBlog


Revision [19439]

Last edited on 2008-01-28 00:16:02 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [17829]

Edited on 2007-12-12 12:38:21 by JavaWoman [preventing unintended wanted pages links]
Additions:
This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding ""<$MTWikifyThis$>"" to the index template within the MTEntry context.
Deletions:
This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.


Revision [16428]

Edited on 2007-04-19 09:07:08 by BrianKoontz [Restored]
Additions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2** & the code published (changes to work with wikka might well be necessary). Copy to this wiki is done in recognition that some code developed in the past (such as happened at WakkaWiki) has been "lost" to general wiki users when the site was shut down & a wish for that not to happen again.

==== Wiki Add ====
(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))

This is a plugin I wrote for Wordpress. It crossposts blogpostings to the Wakka-Wiki (and easily adaptable to Wikka Wiki), and adds links to the blogpost pointing to both the normal view and edit view of the wikipage.

What do you have to do in Wordpress:
- copy the code below and save it as php-file in your plugin-directory;
- change the settings for urls, databases and category id number to be used;
- activate the plugin in your adminscreen;
- edit the index.php file, and add <?php wiki_link($id); ?> after where it says <?php comments_popup_link();?>
- that's it;

The code is Public Domain, feel free to use, add and adapt.

So here's the code:
%%
<?php
/*
Plugin Name: Wikiadd
Plugin URI: http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd
Description: Will crosspost wordpress posts to a wiki as well
Version: 1.0
Author: Ton Zijlstra
Author URI: http://www.zylstra.org/blog
*/
function wiki_link($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//function called from index
//this function creates links to the wiki on the weblogpages

//check if the wiki category was set, which means the post has to be wiki_linked
$wiki_cat = 15 ; // change this to the id number of your category you want to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// construct links one to see wikipage, one to edit, get post title first
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);

// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
// construct the links
$wiki_url = "http://yourdomain.com/wakka/wakka.php?wakka="; // put the base url of your wiki here
$wiki_see = $wiki_url . $wiki_title;
$wiki_edit = $wiki_url . $wiki_title . "/edit";

// print the links to the page
echo("<a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiWorkOnThis</a>");

}
return $post_ID;
}

function wiki_add($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//this function adds the blogpost to the wiki-database

//check if the wiki category was set, which means the post has to be wikified
$wiki_cat = 15 ; // change this to the id number of the category to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// wiki is a category so proceed
// wikifying means 2 steps, 1 alter the original content to include links to the posting
// and step 2 add the wiki-page

// Step 1 Alter the original content to include links to the posting

//get content of post from database
$query1 = "SELECT post_content FROM $tableposts WHERE ID = $post_ID";
$original_content = $wpdb->get_var($query1);


// construct link to post
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);
// add the title as link to the posting
$post_link = "http://yourdomain.com/wordpress/index.php?p=" . $post_ID;
$new_content = "====".$wiki_title."====\r\n".$original_content."\r\n\r\n **This post was blogged
at**:[[".$post_link." your blogname]]";
// now alter the wikititle to create a camelcase handle for it in the wiki
// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
//construct date
$blog_date = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);

// approach database
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query5 = "INSERT INTO extra_pages VALUES
('','$wiki_title','$blog_date','$new_content','','','Hydrogen blog','Y','','','')";
mysql_query($query5);
mysql_close();
} // end wiki is category
return $post_ID;
}
# Turn on the wikifying process.
add_action('publish_post', 'wiki_add','0');
add_action('wikilinker', 'wiki_link');
?>
%%

Wishlist for improvements:

check the wiki before adding a posting to see if the title already is in use
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database

----

====MT Plugin for Wakka Wiki====
(also see [[WikifyingTheBlog]] and [[WikiAdd]])

I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.

In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog. The former (making MT add entries to the wikka database, requires MT version 3 or higher, which I don't use yet. In lower versions this is not possible without digging into the MT core itself.)

This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.

%%
package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );

sub wikifythis {
my $ctx = shift;
my $wikify_entry = $ctx->stash ('entry');
my $wikify_cats = $wikify_entry->categories;
my $cats_number = scalar(@$wikify_cats);
my $test = "no";
my $pointer = 0;
my $wikify_title = $wikify_entry->title;
for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
if (@$wikify_cats[$pointer]->label eq "wikify") {
$test = "yes";}
}
if ($test eq "yes") {
my (@wikify_title_words, $word);
@wikify_title_words = split(/ /,$wikify_title);
my $wikified_title = "";
foreach $word (@wikify_title_words) {
$wikified_title = $wikified_title.ucfirst($word);
}
#build the links to the wiki-page
my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
my $wiki_see = $wiki_baseurl.$wikified_title;
my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
return $result;

}
else {return '';}
}
1;
%%
Deletions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2**


Revision [16425]

Edited on 2007-04-19 08:43:13 by PcxXzf [Restored]
Additions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2**
Deletions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2** & the code published (changes to work with wikka might well be necessary). Copy to this wiki is done in recognition that some code developed in the past (such as happened at WakkaWiki) has been "lost" to general wiki users when the site was shut down & a wish for that not to happen again.

==== Wiki Add ====
(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))

This is a plugin I wrote for Wordpress. It crossposts blogpostings to the Wakka-Wiki (and easily adaptable to Wikka Wiki), and adds links to the blogpost pointing to both the normal view and edit view of the wikipage.

What do you have to do in Wordpress:
- copy the code below and save it as php-file in your plugin-directory;
- change the settings for urls, databases and category id number to be used;
- activate the plugin in your adminscreen;
- edit the index.php file, and add <?php wiki_link($id); ?> after where it says <?php comments_popup_link();?>
- that's it;

The code is Public Domain, feel free to use, add and adapt.

So here's the code:
%%
<?php
/*
Plugin Name: Wikiadd
Plugin URI: http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd
Description: Will crosspost wordpress posts to a wiki as well
Version: 1.0
Author: Ton Zijlstra
Author URI: http://www.zylstra.org/blog
*/
function wiki_link($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//function called from index
//this function creates links to the wiki on the weblogpages

//check if the wiki category was set, which means the post has to be wiki_linked
$wiki_cat = 15 ; // change this to the id number of your category you want to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// construct links one to see wikipage, one to edit, get post title first
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);

// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
// construct the links
$wiki_url = "http://yourdomain.com/wakka/wakka.php?wakka="; // put the base url of your wiki here
$wiki_see = $wiki_url . $wiki_title;
$wiki_edit = $wiki_url . $wiki_title . "/edit";

// print the links to the page
echo("<a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiWorkOnThis</a>");

}
return $post_ID;
}

function wiki_add($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//this function adds the blogpost to the wiki-database

//check if the wiki category was set, which means the post has to be wikified
$wiki_cat = 15 ; // change this to the id number of the category to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// wiki is a category so proceed
// wikifying means 2 steps, 1 alter the original content to include links to the posting
// and step 2 add the wiki-page

// Step 1 Alter the original content to include links to the posting

//get content of post from database
$query1 = "SELECT post_content FROM $tableposts WHERE ID = $post_ID";
$original_content = $wpdb->get_var($query1);


// construct link to post
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);
// add the title as link to the posting
$post_link = "http://yourdomain.com/wordpress/index.php?p=" . $post_ID;
$new_content = "====".$wiki_title."====\r\n".$original_content."\r\n\r\n **This post was blogged
at**:[[".$post_link." your blogname]]";
// now alter the wikititle to create a camelcase handle for it in the wiki
// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
//construct date
$blog_date = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);

// approach database
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query5 = "INSERT INTO extra_pages VALUES
('','$wiki_title','$blog_date','$new_content','','','Hydrogen blog','Y','','','')";
mysql_query($query5);
mysql_close();
} // end wiki is category
return $post_ID;
}
# Turn on the wikifying process.
add_action('publish_post', 'wiki_add','0');
add_action('wikilinker', 'wiki_link');
?>
%%

Wishlist for improvements:

check the wiki before adding a posting to see if the title already is in use
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database

----

====MT Plugin for Wakka Wiki====
(also see [[WikifyingTheBlog]] and [[WikiAdd]])

I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.

In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog. The former (making MT add entries to the wikka database, requires MT version 3 or higher, which I don't use yet. In lower versions this is not possible without digging into the MT core itself.)

This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.

%%
package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );

sub wikifythis {
my $ctx = shift;
my $wikify_entry = $ctx->stash ('entry');
my $wikify_cats = $wikify_entry->categories;
my $cats_number = scalar(@$wikify_cats);
my $test = "no";
my $pointer = 0;
my $wikify_title = $wikify_entry->title;
for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
if (@$wikify_cats[$pointer]->label eq "wikify") {
$test = "yes";}
}
if ($test eq "yes") {
my (@wikify_title_words, $word);
@wikify_title_words = split(/ /,$wikify_title);
my $wikified_title = "";
foreach $word (@wikify_title_words) {
$wikified_title = $wikified_title.ucfirst($word);
}
#build the links to the wiki-page
my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
my $wiki_see = $wiki_baseurl.$wikified_title;
my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
return $result;

}
else {return '';}
}
1;
%%


Revision [10999]

Edited on 2005-09-10 12:03:01 by TonZijlstra [Added some additional info, clarifying instructions]
Additions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2** & the code published (changes to work with wikka might well be necessary). Copy to this wiki is done in recognition that some code developed in the past (such as happened at WakkaWiki) has been "lost" to general wiki users when the site was shut down & a wish for that not to happen again.

==== Wiki Add ====
(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))

This is a plugin I wrote for Wordpress. It crossposts blogpostings to the Wakka-Wiki (and easily adaptable to Wikka Wiki), and adds links to the blogpost pointing to both the normal view and edit view of the wikipage.

What do you have to do in Wordpress:
- copy the code below and save it as php-file in your plugin-directory;
- change the settings for urls, databases and category id number to be used;
- activate the plugin in your adminscreen;
- edit the index.php file, and add <?php wiki_link($id); ?> after where it says <?php comments_popup_link();?>
- that's it;

The code is Public Domain, feel free to use, add and adapt.

So here's the code:
<?php
/*
Plugin Name: Wikiadd
Plugin URI: http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd
Description: Will crosspost wordpress posts to a wiki as well
Version: 1.0
Author: Ton Zijlstra
Author URI: http://www.zylstra.org/blog
*/
function wiki_link($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//function called from index
//this function creates links to the wiki on the weblogpages

//check if the wiki category was set, which means the post has to be wiki_linked
$wiki_cat = 15 ; // change this to the id number of your category you want to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// construct links one to see wikipage, one to edit, get post title first
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);

// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
// construct the links
$wiki_url = "http://yourdomain.com/wakka/wakka.php?wakka="; // put the base url of your wiki here
$wiki_see = $wiki_url . $wiki_title;
$wiki_edit = $wiki_url . $wiki_title . "/edit";

// print the links to the page
echo("<a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiWorkOnThis</a>");

}
return $post_ID;
}

function wiki_add($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//this function adds the blogpost to the wiki-database

//check if the wiki category was set, which means the post has to be wikified
$wiki_cat = 15 ; // change this to the id number of the category to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// wiki is a category so proceed
// wikifying means 2 steps, 1 alter the original content to include links to the posting
// and step 2 add the wiki-page

// Step 1 Alter the original content to include links to the posting

//get content of post from database
$query1 = "SELECT post_content FROM $tableposts WHERE ID = $post_ID";
$original_content = $wpdb->get_var($query1);


// construct link to post
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);
// add the title as link to the posting
$post_link = "http://yourdomain.com/wordpress/index.php?p=" . $post_ID;
$new_content = "====".$wiki_title."====\r\n".$original_content."\r\n\r\n **This post was blogged
at**:[[".$post_link." your blogname]]";
// now alter the wikititle to create a camelcase handle for it in the wiki
// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
//construct date
$blog_date = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);

// approach database
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query5 = "INSERT INTO extra_pages VALUES
('','$wiki_title','$blog_date','$new_content','','','Hydrogen blog','Y','','','')";
mysql_query($query5);
mysql_close();
} // end wiki is category
return $post_ID;
}
# Turn on the wikifying process.
add_action('publish_post', 'wiki_add','0');
add_action('wikilinker', 'wiki_link');
?>

Wishlist for improvements:

check the wiki before adding a posting to see if the title already is in use
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database

----

====MT Plugin for Wakka Wiki====
(also see [[WikifyingTheBlog]] and [[WikiAdd]])

I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.

In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog. The former (making MT add entries to the wikka database, requires MT version 3 or higher, which I don't use yet. In lower versions this is not possible without digging into the MT core itself.)

This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.

package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );

sub wikifythis {
my $ctx = shift;
my $wikify_entry = $ctx->stash ('entry');
my $wikify_cats = $wikify_entry->categories;
my $cats_number = scalar(@$wikify_cats);
my $test = "no";
my $pointer = 0;
my $wikify_title = $wikify_entry->title;
for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
if (@$wikify_cats[$pointer]->label eq "wikify") {
$test = "yes";}
}
if ($test eq "yes") {
my (@wikify_title_words, $word);
@wikify_title_words = split(/ /,$wikify_title);
my $wikified_title = "";
foreach $word (@wikify_title_words) {
$wikified_title = $wikified_title.ucfirst($word);
}
#build the links to the wiki-page
my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
my $wiki_see = $wiki_baseurl.$wikified_title;
my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
return $result;

}
else {return '';}
}
1;
Deletions:
This page is copied from the [[http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd TonExtraWiki]] where it was first **developed for wakka 0.1.2** & the code published (changes to work with wikka might well be necessary). Copy to this wiki is done in recognition that some code developed in the past (such as happened at WakkaWiki) has been "lost" to general wiki users when the site was shut down & a wish for that not to happen again.

==== Wiki Add ====
(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))

This is a plugin I wrote for Wordpress. It crossposts blogpostings to the Wakka-Wiki (and easily adaptable to Wikka Wiki), and adds links to the blogpost pointing to both the normal view and edit view of the wikipage.

What do you have to do:
- copy the code below and save it as php-file in your plugin-directory;
- change the settings for urls, databases and category id number to be used;
- activate the plugin in your adminscreen;
- edit the index.php file, and add <?php wiki_link($id); ?> after where it says <?php comments_popup_link();?>
- that's it;

The code is Public Domain, feel free to use, add and adapt.

So here's the code:
%%
<?php
/*
Plugin Name: Wikiadd
Plugin URI: http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd
Description: Will crosspost wordpress posts to a wiki as well
Version: 1.0
Author: Ton Zijlstra
Author URI: http://www.zylstra.org/blog
*/
function wiki_link($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//function called from index
//this function creates links to the wiki on the weblogpages

//check if the wiki category was set, which means the post has to be wiki_linked
$wiki_cat = 15 ; // change this to the id number of your category you want to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// construct links one to see wikipage, one to edit, get post title first
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);

// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
// construct the links
$wiki_url = "http://yourdomain.com/wakka/wakka.php?wakka="; // put the base url of your wiki here
$wiki_see = $wiki_url . $wiki_title;
$wiki_edit = $wiki_url . $wiki_title . "/edit";

// print the links to the page
echo("<a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiWorkOnThis</a>");

}
return $post_ID;
}

function wiki_add($post_ID) {
global $wpdb, $tableposts, $tablepost2cat;
//this function adds the blogpost to the wiki-database

//check if the wiki category was set, which means the post has to be wikified
$wiki_cat = 15 ; // change this to the id number of the category to be wikified
$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
$exists = $wpdb->get_var($query2);

if (!empty($exists)) {
// wiki is a category so proceed
// wikifying means 2 steps, 1 alter the original content to include links to the posting
// and step 2 add the wiki-page

// Step 1 Alter the original content to include links to the posting

//get content of post from database
$query1 = "SELECT post_content FROM $tableposts WHERE ID = $post_ID";
$original_content = $wpdb->get_var($query1);


// construct link to post
$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
$wiki_title = $wpdb->get_var($query3);
// add the title as link to the posting
$post_link = "http://yourdomain.com/wordpress/index.php?p=" . $post_ID;
$new_content = "====".$wiki_title."====\r\n".$original_content."\r\n\r\n **This post was blogged
at**:[[".$post_link." your blogname]]";
// now alter the wikititle to create a camelcase handle for it in the wiki
// in the wiki_title spaces will be replaced by capping the next letter
$title_array = str_word_count($wiki_title,1);
$wiki_title = "";
$numElement = count($title_array);
for ($pointer = 0; $pointer < $numElement; $pointer ++) {
$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
}
//construct date
$blog_date = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);

// approach database
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query5 = "INSERT INTO extra_pages VALUES
('','$wiki_title','$blog_date','$new_content','','','Hydrogen blog','Y','','','')";
mysql_query($query5);
mysql_close();
} // end wiki is category
return $post_ID;
}
# Turn on the wikifying process.
add_action('publish_post', 'wiki_add','0');
add_action('wikilinker', 'wiki_link');
?>
%%

Wishlist for improvements:

check the wiki before adding a posting to see if the title already is in use
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database

----

====MT Plugin for Wakka Wiki====
(also see [[WikifyingTheBlog]] and [[WikiAdd]])

I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.

In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog.

This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.

%%
package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );

sub wikifythis {
my $ctx = shift;
my $wikify_entry = $ctx->stash ('entry');
my $wikify_cats = $wikify_entry->categories;
my $cats_number = scalar(@$wikify_cats);
my $test = "no";
my $pointer = 0;
my $wikify_title = $wikify_entry->title;
for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
if (@$wikify_cats[$pointer]->label eq "wikify") {
$test = "yes";}
}
if ($test eq "yes") {
my (@wikify_title_words, $word);
@wikify_title_words = split(/ /,$wikify_title);
my $wikified_title = "";
foreach $word (@wikify_title_words) {
$wikified_title = $wikified_title.ucfirst($word);
}
#build the links to the wiki-page
my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
my $wiki_see = $wiki_baseurl.$wikified_title;
my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
return $result;

}
else {return '';}
}
1;


Revision [2989]

Edited on 2004-12-08 23:16:31 by GmBowen [code development for wakka]
Additions:
(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database
%%
Deletions:
(also see [WikifyingTheBlog (at [[http://www.zylstra.org/extra/wakka.php?wakka=WikifyingTheBlog TonExtraWiki]]) and [MTPluginWiki] (see below on this page now))
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database


Revision [2988]

Edited on 2004-12-08 23:12:22 by GmBowen [code developed for wakka]
Additions:
(also see [WikifyingTheBlog (at [[http://www.zylstra.org/extra/wakka.php?wakka=WikifyingTheBlog TonExtraWiki]]) and [MTPluginWiki] (see below on this page now))
----
====MT Plugin for Wakka Wiki====
(also see [[WikifyingTheBlog]] and [[WikiAdd]])
I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.
In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog.
This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.
package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );
sub wikifythis {
my $ctx = shift;
my $wikify_entry = $ctx->stash ('entry');
my $wikify_cats = $wikify_entry->categories;
my $cats_number = scalar(@$wikify_cats);
my $test = "no";
my $pointer = 0;
my $wikify_title = $wikify_entry->title;
for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
if (@$wikify_cats[$pointer]->label eq "wikify") {
$test = "yes";}
if ($test eq "yes") {
my (@wikify_title_words, $word);
@wikify_title_words = split(/ /,$wikify_title);
my $wikified_title = "";
foreach $word (@wikify_title_words) {
$wikified_title = $wikified_title.ucfirst($word);
#build the links to the wiki-page
my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
my $wiki_see = $wiki_baseurl.$wikified_title;
my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
return $result;
else {return '';}
1;
Deletions:
(also see [[WikifyingTheBlog]] and [[MTPluginWiki]])


Revision [2987]

The oldest known version of this page was created on 2004-12-08 23:09:07 by GmBowen [code developed for wakka]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki