<?php
/**
* Table Tag Plugin v1.2 for MyBB PR2
* Copyright © 2005
*
* By: Shochu
* Special thanks to the creator of sorttable.js
* http://www.kryogenix.org/code/browser/sorttable/
*
* Website: http://mods.mybboard.com
* http://www.mybboard.com
* Version History
* 1.0: Release
* 1.1: Bug Fix for Multiple Tables in a single post
* 1.2: You must now specify tables as sortable using the [table=sortable] tag.
*/
if(!defined("IN_MYBB"))
{
die("This file cannot be accessed directly.");
}
$plugins->add_hook("parse_message", "table_tag");
function table_tag_info()
{
return array(
"name" => "Table Tag",
"description" => "Fügt den Table Tag ins Forum ein ([table] [tr] [td]), so dass Tabellen in Beiträgen genutzt werden können.",
"website" => "http://community.mybboard.net/",
"author" => "Shochu",
"authorsite" => "http://community.mybboard.net/",
"version" => "1.2",
);
}
function table_tag_activate()
{
require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
global $db;
$table_tag_group = array(
"gid" => "NULL",
"name" => "Table Tag Einstellungen",
"description" => "Einstellungen für das Table Tag Plugin",
"disporder" => "3",
"isdefault" => "no",
);
$db->insert_query(TABLE_PREFIX."settinggroups", $table_tag_group);
$gid = $db->insert_id();
$table_tag_setting_1 = array(
"sid" => "NULL",
"name" => "activate_table_tag",
"title" => "Table Tag Plugin aktivieren",
"description" => "Table Tag Plugin aktivieren?",
"optionscode" => "onoff",
"value" => "on",
"disporder" => "1",
"gid" => intval($gid),
);
$table_tag_setting_2 = array(
"sid" => "NULL",
"name" => "activate_javascript",
"title" => "Javascript aktivieren?",
"description" => "Javascript aktivieren, um Tabellensortierung einzuschalten?",
"optionscode" => "onoff",
"value" => "off",
"disporder" => "2",
"gid" => intval($gid),
);
$table_tag_setting_3 = array(
"sid" => "NULL",
"name" => "table_css",
"title" => "Table Tag CSS [TABLE]",
"description" => "CSS für den <table> Tag",
"optionscode" => "textarea",
"value" => "border-width: 0 0 1px 1px; \nborder-style: solid; \nborder-collapse: collapse;",
"disporder" => "3",
"gid" => intval($gid),
);
$table_tag_setting_4 = array(
"sid" => "NULL",
"name" => "th_css",
"title" => "Tabellen Header Tag CSS [TH]",
"description" => "CSS für den <th> (table header) Tag",
"optionscode" => "textarea",
"value" => "border-width: 1px 1px 0 0; \nborder-color: #000000; \nborder-style: solid; \nmargin: 0; \npadding: 4px; \nbackground-color: #c0c0c0;",
"disporder" => "4",
"gid" => intval($gid),
);
$table_tag_setting_5 = array(
"sid" => "NULL",
"name" => "tr_css",
"title" => "Tabellen-Reihe Tag CSS [TR]",
"description" => "CSS für den <tr> (table row) Tag",
"optionscode" => "textarea",
"value" => "",
"disporder" => "5",
"gid" => intval($gid),
);
$table_tag_setting_6 = array(
"sid" => "NULL",
"name" => "td_css",
"title" => "Tabellen-Daten Tag CSS [TD]",
"description" => "CSS für den <td> (table data) Tag",
"optionscode" => "textarea",
"value" => "border-width: 1px 1px 0 0; \nborder-color: #000000; \nborder-style: solid; \nmargin: 0; \npadding: 4px; \nbackground-color: #6666CC;",
"disporder" => "6",
"gid" => intval($gid),
);
$table_tag_setting_7 = array(
"sid" => "NULL",
"name" => "td_shaded_css",
"title" => "Tabellen-Daten Tag CSS [TD=shaded]",
"description" => "CSS für den <td> (table data) Tag (schattiert)",
"optionscode" => "textarea",
"value" => "border-width: 1px 1px 0 0; \nborder-color: #000000; \nborder-style: solid; \nmargin: 0; \npadding: 4px; \nbackground-color: #c0ffc0;",
"disporder" => "7",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_1);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_2);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_3);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_4);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_5);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_6);
$db->insert_query(TABLE_PREFIX."settings", $table_tag_setting_7);
rebuild_settings();
}
function table_tag_deactivate()
{
require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('activate_table_tag', 'activate_javascript', 'table_css', 'tr_css', 'td_css', 'th_css', 'td_shaded_css')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='Table Tag Einstellungen'");
// Rebuilt settings.php
rebuild_settings();
}
function table_tag($message)
{
global $mybb;
//Check is the plugin is turned on
if(($mybb->settings['activate_table_tag'] == 'on')){
//get user settings
$table_css = preg_replace( '/[\n\r]+/is', '', $mybb->settings['table_css']);
$tr_css = preg_replace( '/[\n\r]+/is', '', $mybb->settings['tr_css']);
$td_css = preg_replace( '/[\n\r]+/is', '', $mybb->settings['td_css']);
$th_css = preg_replace( '/[\n\r]+/is', '', $mybb->settings['th_css']);
$td_shaded_css = preg_replace( '/[\n\r]+/is', '', $mybb->settings['td_shaded_css']);
//Remove linebreaks so we don't have lots of <br> in our message
$message = preg_replace("#\[table\](.*?)\[/table\]#esi", "clearnewlines(\"$1\",\"0\")" ,$message);
$message = preg_replace("#\[table=sortable\](.*?)\[/table\]#esi", "clearnewlines(\"$1\",\"1\")" ,$message);
if($mybb->settings['activate_javascript'] == 'on'){
//[table=sortable]
$message = preg_replace("#\[table=sortable\](.*?)\[/table\]#esi", "createtableid(\"$1\", \"$table_css\")" ,$message);
//[table]
$message = preg_replace("#\[table\](.*?)\[/table\]#si", "<table style='$table_css'>$1</table>" ,$message);
}
else{
//[table] Unsortable table
$table_pattern = "#\[table\](.*?)\[/table\]#si";
$table_replace = "<table style='$table_css'>$1</table>";
$message = preg_replace($table_pattern, $table_replace, $message);
}
//<tr>
$table_pattern = "#\[tr\](.*?)\[/tr\]#si";
$table_replace = "<tr style='$tr_css'>$1</tr>";
$message = preg_replace($table_pattern, $table_replace, $message);
//<td>
$table_pattern = "#\[td\](.*?)\[/td\]#si";
$table_replace = "<td style='$td_css'>$1</td>";
$message = preg_replace($table_pattern, $table_replace, $message);
//<td> shaded
$table_pattern = "#\[td=shaded\](.*?)\[/td\]#si";
$table_replace = "<td style='$td_shaded_css'>$1</td>";
$message = preg_replace($table_pattern, $table_replace, $message);
//<th>
$table_pattern = "#\[th\](.*?)\[/th\]#si";
$table_replace = "<th style='$th_css'>$1</th>";
$message = preg_replace($table_pattern, $table_replace, $message);
}
return $message;
}
function clearnewlines($message, $is_sortable)
{
$message = preg_replace( '/[\n\r]+/is', '', $message);
if($is_sortable){
$message = "[table=sortable]".$message."[/table]";
}
else{
$message = "[table]".$message."[/table]";
}
return $message;
}
function createtableid($message, $table_css)
{
static $id_num = 0;
$id_num++;
$id = "table_tag_".$id_num;
$message = "<table class='sortable' id='$id' style='$table_css'>$message</table>";
return $message;
}
if(!function_exists("rebuild_settings"))
{
function rebuild_settings()
{
global $db;
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."settings ORDER BY title ASC");
while($setting = $db->fetch_array($query))
{
$setting['value'] = addslashes($setting['value']);
$settings .= "\$settings['".$setting['name']."'] = \"".$setting['value']."\";\n";
}
$settings = "<?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n?>";
$file = fopen(MYBB_ROOT."/inc/settings.php", "w");
fwrite($file, $settings);
fclose($file);
}
}
?>