Revision [2987]
This is an old revision of WikkaBlog made by GmBowen on 2004-12-08 23:09:07.
Wiki Add
(also see WikifyingTheBlog and MTPluginWiki)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