';
}
### Create Text Domain For Translations
add_action('init', 'bbld_textdomain');
function bbld_textdomain() {
load_plugin_textdomain('bbpress-latest-discussion', false, 'bbpress-latest-discussion');
}
### Function: Install BbLD Configuration
$install = (basename($_SERVER['SCRIPT_NAME']) == 'plugins.php' && (isset($_GET['activate']) || isset($_GET['activate-multi'])));
if ($install) {
bbld_install();
}
function bbld_install() {
global $BbLD_version;
$bbld_option = get_option('bbld_option');
if ($bbld_option['status'] == FALSE) {
$bbld_option['version'] = $BbLD_version;
$bbld_option['url'] = get_settings('home') . '/bbpress';
$bbld_option['limit'] = 10;
$bbld_option['prefix'] = 'bb_';
$bbld_option['trim'] = 100;
$bbld_option['exdb'] = false;
$bbld_option['share'] = false;
$bbld_option['dbuser'] = DB_USER;
$bbld_option['dbpass'] = DB_PASSWORD;
$bbld_option['dbname'] = DB_NAME;
$bbld_option['dbhost'] = DB_HOST;
$bbld_option['status'] = 'install';
$bbld_option['donate'] = false;
$bbld_option['slug'] = 'no';
$bbld_option['exclude'] = '';
$bbld_option['utf8'] = '';
$bbld_template['header'] = '
%BBLD_TITLE%
| %BBLD_TOPIC% | %BBLD_POST% | %BBLD_LPOSTER% |
';
$bbld_template['body'] = '| %BBLD_TOPIC% | %BBLD_POST% | %BBLD_LPOSTER% |
';
$bbld_template['footer'] = '
';
$bbld_template['widget'] = 'Forum Last %BBLD_LIMIT% Discussions';
$bbld_template['sidebar'] = 'Forum Last %BBLD_LIMIT% Discussions
';
$bbld_template['sidedisplay'] = '%BBLD_TOPIC%
Last Post By: %BBLD_LPOSTER%
Inside: %BBLD_FORUM%';
$bbld_template['forum_norm_head'] = 'Forum List
';
$bbld_template['forumwidget'] = '%BBLD_FORUM% (%BBLD_POST%)
%BBLD_FDESC%';
$bbld_template['forum_head'] = 'Forum List';
$bbld_template['forum_header'] = 'Forums
| Main Theme | Topics | Posts |
';
$bbld_template['forum_body'] = '| %BBLD_FORUM% | %BBLD_TOPIC% | %BBLD_POST% |
';
$bbld_template['forum_footer'] = '
';
update_option('bbld_option', $bbld_option);
update_option('bbld_template', $bbld_template);
}
}
### Function: Add Option Page
add_action('admin_menu', 'wpbb_add_pages');
function wpbb_add_pages() {
add_options_page(__("BBpress Latest Discussions Option", 'bbpress-latest-discussion'), __('BbLD Option', 'bbpress-latest-discussion'), 8, __FILE__, 'wp_bb_option');
}
add_filter('plugin_row_meta', 'wpbb_plugin_links' ,10,2);
function wpbb_plugin_links($links, $file) {
$base = plugin_basename(__FILE__);
if ($file == $base) {
$links[] = '' . __('Settings') . '';
$links[] = '' . __('Support') . '';
}
return $links;
}
### Function: Trim some text
function wpbb_trim($paragraph, $limit) {
$original = strlen($paragraph);
if ($original > $limit) {
$text = substr($paragraph, 0, $limit) . " [...]";
}
else {
$text = $paragraph;
}
return $text;
}
### Function: Permalink Data
function wpbb_permalink($type,$topicid, $slug = '',$total = 0,$limit = 30, $forumslug = '') {
global $wpdb,$BbLD_version;
//echo '';
if ($total > $limit) {
$math_bbld = $total / $limit;
$pageno = round($math_bbld);
if ($math_bbld > $pageno) {
$pageno = $pageno + 1;
}
}
$bbld_option = get_option('bbld_option');
if ($bbld_option['slug'] == 1) {
if ($pageno) {
$pagee = '/page/'.$pageno;
}
$permalink = $bbld_option['url'] . '/'. $type . '/' . $topicid . $pagee;
}
elseif ($bbld_option['slug'] == 'slug') {
if ($type == 'topic') {
if ($pageno) {
$pagee = '/page/'.$pageno;
}
$permalink = $bbld_option['url'] . '/topic/' . $slug . $pagee;
}
else {
$permalink = $bbld_option['url'] . '/forum/' . $slug;
}
}
elseif ($bbld_option['slug'] == 'buddypress') {
if ($type == 'topic') {
$bp_group = str_replace("-forum", "", $forumslug);
$bp_group = str_replace("amp-", "", $bp_group);
$bp_group = str_replace("-amp", "", $bp_group);
if (BP_VERSION >= 1.1) {
$permalink = get_settings('home') . '/'. BP_GROUPS_SLUG . '/' . $bp_group . '/forum/topic/' . $slug;
}
else {
$permalink = get_settings('home') . '/'. BP_GROUPS_SLUG . '/' . $bp_group . '/forum/topic/' . $topicid;
}
}
else {
$bp_group = str_replace("-forum", "", $slug);
$bp_group = str_replace("amp-", "", $bp_group);
$bp_group = str_replace("-amp", "", $bp_group);
$permalink = get_settings('home') . '/'. BP_GROUPS_SLUG . '/' . $bp_group . '/forum/';
}
}
else {
if ($pageno) {
$pagee = '&page='.$pageno;
}
$permalink = $bbld_option['url'] . '/'. $type . '.php?id=' . $topicid . $pagee;
}
return $permalink;
}
### Function: Filter forum to exclude some forum
function bbld_filter_forums() {
global $wpdb;
$bbld_option = get_option('bbld_option');
$exclude_chk = $bbld_option['exclude'];
if ($exclude_chk) {
foreach($exclude_chk as $request) {
$forum_ids .= $request.'\',\'';
}
$forum_ids = rtrim($forum_ids, ',\'\' ');
$where = "AND ".$bbld_option['prefix']."topics.forum_id NOT IN ('$forum_ids')";
return $where;
}
}
### Function: Get forum data
function bbld_getdata($type,$forum_slimit = 0, $exclude = 0) {
global $wpdb,$exbbdb,$table_prefix;
$bbld_option = get_option('bbld_option');
if ($bbld_option['exdb']) {
$exbbdb = new wpdb($bbld_option['dbuser'], $bbld_option['dbpass'], $bbld_option['dbname'], $bbld_option['dbhost']);
}
if ($type == 'topic') {
if ($exclude != 0) {
$filter = "AND ".$bbld_option['prefix']."topics.forum_id IN ('$exclude')";
}
else {
$filter = bbld_filter_forums();
}
if (!$bbld_option['share']) {
$bbld_userdata = "JOIN ".$bbld_option['prefix']."users ON ".$bbld_option['prefix']."topics.topic_last_poster = ".$bbld_option['prefix']."users.ID";
}
if ($bbld_option['exdb']) {
$bbtopic = $exbbdb->get_results("SELECT * FROM ".$bbld_option['prefix']."topics JOIN ".$bbld_option['prefix']."forums ON ".$bbld_option['prefix']."topics.topic_status = '0' AND ".$bbld_option['prefix']."topics.forum_id = ".$bbld_option['prefix']."forums.forum_id ".$bbld_userdata." ".$filter." ORDER BY topic_time DESC LIMIT $forum_slimit");
}
else {
$bbtopic = $wpdb->get_results("SELECT * FROM ".$bbld_option['prefix']."topics JOIN ".$bbld_option['prefix']."forums ON ".$bbld_option['prefix']."topics.topic_status = '0' AND ".$bbld_option['prefix']."topics.forum_id = ".$bbld_option['prefix']."forums.forum_id ".$bbld_userdata." ".$filter." ORDER BY topic_time DESC LIMIT $forum_slimit");
}
}
elseif ($type == 'utf8') {
if ($bbld_option['exdb']) {
$bbld_var = $exbbdb->get_var("SELECT count(*) FROM ".$bbld_option['prefix']."topics");
$bbld_random = rand(1,$bbld_var);
$bbtopic = $exbbdb->get_row("SELECT * FROM ".$bbld_option['prefix']."topics WHERE topic_id = ".$bbld_random." LIMIT 1");
}
else {
$bbld_var = $wpdb->get_var("SELECT count(*) FROM ".$bbld_option['prefix']."topics");
$bbld_random = rand(1,$bbld_var);
$bbtopic = $wpdb->get_row("SELECT * FROM ".$bbld_option['prefix']."topics WHERE topic_id = ".$bbld_random." LIMIT 1");
}
}
elseif ($type == 'meta') {
if ($bbld_option['exdb']) {
if ($bbld_option['9.0.4']) {
$bbtopic = $exbbdb->get_row("SELECT * FROM ".$bbld_option['prefix']."topicmeta WHERE ".$bbld_option['prefix']."topicmeta.meta_key = 'page_topics' LIMIT 1");
}
else {
$bbtopic = $exbbdb->get_row("SELECT * FROM ".$bbld_option['prefix']."meta WHERE ".$bbld_option['prefix']."meta.meta_key = 'page_topics' LIMIT 1");
}
}
else {
if ($bbld_option['9.0.4']) {
$bbtopic = $wpdb->get_row("SELECT * FROM ".$bbld_option['prefix']."topicmeta WHERE ".$bbld_option['prefix']."topicmeta.meta_key = 'page_topics' LIMIT 1");
}
else {
$bbtopic = $wpdb->get_row("SELECT * FROM ".$bbld_option['prefix']."meta WHERE ".$bbld_option['prefix']."meta.meta_key = 'page_topics' LIMIT 1");
}
}
}
else {
if (!is_admin()) {
$filter = bbld_filter_forums();
$filter = str_replace("AND", "WHERE", $filter);
$filter = str_replace("topics", "forums", $filter);
}
if ($bbld_option['exdb']) {
$bbtopic = $exbbdb->get_results("SELECT * FROM ".$bbld_option['prefix']."forums ".$filter." ORDER BY forum_order ASC");
}
else {
$bbtopic = $wpdb->get_results("SELECT * FROM ".$bbld_option['prefix']."forums ".$filter." ORDER BY forum_order ASC");
}
}
return $bbtopic;
}
### Function: Donate a link back.
function bbld_donate() {
echo 'Powered By BbLD
';
}
### Function: Convert Data Into UTF-8
function bbld_utf8($data, $charset) {
if ($charset) {
if (function_exists('mb_check_encoding')) {
if (mb_check_encoding($data,"UTF-8") == FALSE) {
$data = utf8_encode($data);
if (function_exists('iconv')) {
$string = iconv("UTF-8", $charset."//TRANSLIT", $data);
}
}
else {
if (function_exists('iconv')) {
$string = iconv("UTF-8", $charset."//TRANSLIT", $data);
}
}
}
}
else {
$string = $data;
}
if (!$string) { $string = $data; }
return $string;
}
### Function: BBpress display name For Version 0.9.0.*
function bbld_intergrated($id,$name,$email,$display = '') {
global $wpdb,$table_prefix;
$bbld_option = get_option('bbld_option');
if ($bbld_option['share']) {
$user_forum_data = get_userdata($id);
if ($user_forum_data->display_name) {
$user['name'] = $user_forum_data->display_name;
}
else {
$user['name'] = $name;
}
$user['id'] = $id;
$user['email'] = $user_forum_data->user_email;
}
else {
if (!$display) {
$user['name'] = $name;
}
else {
$user['name'] = $display;
}
$user['email'] = $email;
$user['id'] = $id;
}
return $user;
}
### Function: BBpress Latest Discussions Page Display
function wp_bb_get_discuss($exclude = 0) {
global $table_prefix,$wpdb,$user_data;
$bbld_option = get_option('bbld_option');
$bbtopic = bbld_getdata('topic',$bbld_option['limit'],$exclude);
$bb_meta = bbld_getdata('meta');
$meta_value = $bb_meta->meta_value;
if (!$meta_value) { $meta_value = 30; }
$bbld_template = get_option('bbld_template');
if ($bbtopic) {
$template_data_head = stripslashes($bbld_template['header']);
$template_data_head = str_replace("%BBLD_TITLE%", __("Discussion Forum", 'bbpress-latest-discussion'), $template_data_head);
$template_data_head = str_replace("%BBLD_TOPIC%", __("Topic", 'bbpress-latest-discussion'), $template_data_head);
$template_data_head = str_replace("%BBLD_POST%", __("Posts", 'bbpress-latest-discussion'), $template_data_head);
$template_data_head = str_replace("%BBLD_LPOSTER%", __("Last Poster", 'bbpress-latest-discussion'), $template_data_head);
echo $template_data_head;
$misc_no = 0;
foreach ( $bbtopic as $bbtopic ) {
if ($misc_no == 0) {
$misc_no = $misc_no + 1;
$tr_class = 'alt';
}
else {
$misc_no = $misc_no - 1;
$tr_class = 'alt1';
}
$title_text = bbld_utf8(html_entity_decode(htmlspecialchars_decode(stripslashes($bbtopic->topic_title), ENT_QUOTES), ENT_QUOTES, $bbld_option['utf8']), $bbld_option['utf8']);
$title_text = wpbb_trim($title_text, $bbld_option['trim']);
$user_data = bbld_intergrated($bbtopic->topic_last_poster,$bbtopic->topic_last_poster_name,$bbtopic->user_email,$bbtopic->display_name);
$template_data_body = stripslashes($bbld_template['body']);
// Filter function
$template_data_body = apply_filters('bbld_page', $template_data_body);
// Filter function
$template_data_body = str_replace("%BBLD_CLASS%", $tr_class, $template_data_body);
$template_data_body = str_replace("%BBLD_URL%", wpbb_permalink('topic',$bbtopic->topic_id,$bbtopic->topic_slug,$bbtopic->topic_posts,$meta_value,$bbtopic->forum_slug).'#post-'.$bbtopic->topic_last_post_id, $template_data_body);
$template_data_body = str_replace("%BBLD_TOPIC%", $title_text, $template_data_body);
$template_data_body = str_replace("%BBLD_POST%", $bbtopic->topic_posts, $template_data_body);
$template_data_body = str_replace("%BBLD_LPOSTER%", $user_data['name'], $template_data_body);
echo $template_data_body;
}
echo stripslashes($bbld_template['footer']);
if ($bbld_option['donate']) {
bbld_donate();
}
}
else {
echo 'It Seem There Is Something Wrong With BBLD Configuration, Please Check It.
';
}
}
### Function: BBpress Forum List code
function bbld_getforum($widget = 0) {
global $table_prefix,$wpdb,$user_data;
$bbforum = bbld_getdata('exclude');
$bbld_option = get_option('bbld_option');
$bbld_template = get_option('bbld_template');
if ($widget == 0) {
$template_data_head = stripslashes($bbld_template['forum_header']);
echo $template_data_head;
}
if ($bbforum) {
foreach ($bbforum as $forum) {
if ($misc_no == 0) {
$misc_no = $misc_no + 1;
$tr_class = 'alt';
}
else {
$misc_no = $misc_no - 1;
$tr_class = 'alt1';
}
$forum_name = bbld_utf8($forum->forum_name, $bbld_option['utf8']);
$forum_desc = bbld_utf8($forum->forum_desc, $bbld_option['utf8']);
$forum_topics = $forum->topics;
$forum_posts = $forum->posts;
$forum_url = wpbb_permalink('forum',$forum->forum_id,$forum->forum_slug);
if ($widget == 1) {
$template_data = stripslashes($bbld_template['forumwidget']);
}
else {
$template_data = stripslashes($bbld_template['forum_body']);
}
// Filter function
$template_data = apply_filters('bbld_forum', $template_data);
// Filter function
$template_data = str_replace("%BBLD_CLASS%", $tr_class, $template_data);
$template_data = str_replace("%BBLD_FORUM%", $forum_name, $template_data);
$template_data = str_replace("%BBLD_FURL%", $forum_url, $template_data);
$template_data = str_replace("%BBLD_TOPIC%", $forum_topics, $template_data);
$template_data = str_replace("%BBLD_POST%", $forum_posts, $template_data);
$template_data = str_replace("%BBLD_FDESC%", $forum_desc, $template_data);
echo $template_data;
}
}
else {
echo 'It Seem There Is Something Wrong With BBLD Configuration, Please Check It.
';
}
if ($widget == 0) {
$template_data_foot = stripslashes($bbld_template['forum_footer']);
echo $template_data_foot;
}
}
### Function: BBpress Latest Discussions Sidebar code
function bbld_getside() {
global $table_prefix,$wpdb,$user_data;
$bbld_option = get_option('bbld_option');
$bbtopic = bbld_getdata('topic',$bbld_option['limit']);
$bb_meta = bbld_getdata('meta');
$meta_value = $bb_meta->meta_value;
if (!$meta_value) { $meta_value = 30; }
$bbld_template = get_option('bbld_template');
if ($bbtopic) {
foreach ( $bbtopic as $bbtopic ) {
$title_text = bbld_utf8(html_entity_decode(htmlspecialchars_decode(stripslashes($bbtopic->topic_title), ENT_QUOTES), ENT_QUOTES, $bbld_option['utf8']), $bbld_option['utf8']);
$title_text = wpbb_trim($title_text, $bbld_option['trim']);
$forum_url = wpbb_permalink('forum',$bbtopic->forum_id,$bbtopic->forum_slug);
$user_data = bbld_intergrated($bbtopic->topic_last_poster,$bbtopic->topic_last_poster_name,$bbtopic->user_email,$bbtopic->display_name);
$template_data_sidebar = stripslashes($bbld_template['sidedisplay']);
// Filter function
$template_data_sidebar = apply_filters('bbld_sidebar', $template_data_sidebar);
// Filter function
$template_data_sidebar = str_replace("%BBLD_URL%", wpbb_permalink('topic',$bbtopic->topic_id,$bbtopic->topic_slug,$bbtopic->topic_posts,$meta_value,$bbtopic->forum_slug).'#post-'.$bbtopic->topic_last_post_id, $template_data_sidebar);
$template_data_sidebar = str_replace("%BBLD_TOPIC%", $title_text, $template_data_sidebar);
$template_data_sidebar = str_replace("%BBLD_POST%", $bbtopic->topic_posts, $template_data_sidebar);
$template_data_sidebar = str_replace("%BBLD_FURL%", $forum_url, $template_data_sidebar);
if ($user_data['email']) {
$template_data_sidebar = str_replace("%GRAVATAR%", get_avatar($user_data['email'],32), $template_data_sidebar);
}
$forum_name = bbld_utf8($bbtopic->forum_name, $bbld_option['utf8']);
$template_data_sidebar = str_replace("%BBLD_FORUM%", $forum_name, $template_data_sidebar);
$template_data_sidebar = str_replace("%BBLD_LPOSTER%", $user_data['name'], $template_data_sidebar);
echo $template_data_sidebar;
}
}
else {
echo 'It Seem There Is Something Wrong With BBLD Configuration, Please Check It.
';
}
}
### Function: BBpress Forum List Display
function wp_bb_get_forum_sidebar() {
global $table_prefix,$wpdb;
$bbld_template = get_option('bbld_template');
$bbld_option = get_option('bbld_option');
$template_sidebar = stripslashes($bbld_template['forum_norm_head']);
echo $template_sidebar;
echo '';
bbld_getforum(1);
echo "
";
if ($bbld_option['donate']) {
bbld_donate();
}
}
### Function: BBpress Forum List Sidebar Widget
function bbld_forum_widget($args) {
global $table_prefix,$wpdb;
$bbld_template = get_option('bbld_template');
$bbld_option = get_option('bbld_option');
extract($args);
echo $before_widget;
echo $before_title . $bbld_template['forum_head'] . $after_title;
echo '';
bbld_getforum(1);
echo "
";
echo $after_widget;
if ($bbld_option['donate']) {
bbld_donate();
}
}
### Function: BBpress Forum List Sidebar Widget Control
function bbld_forum_control() {
$bbld_template = get_option('bbld_template');
if ($_POST['bbld_widget_submit']) {
$bbld_template['forum_head'] = $_POST['bbld_widget_title'];
update_option('bbld_template', $bbld_template);
}
echo '
';
}
### Function: BBpress Latest Discussions Sidebar Display
function wp_bb_get_discuss_sidebar() {
global $table_prefix,$wpdb;
$bbld_template = get_option('bbld_template');
$bbld_option = get_option('bbld_option');
$template_sidebar = stripslashes($bbld_template['sidebar']);
$template_sidebar = str_replace("%BBLD_LIMIT%", $bbld_option['limit'], $template_sidebar);
echo $template_sidebar;
echo '';
bbld_getside();
echo "
";
if ($bbld_option['donate']) {
bbld_donate();
}
}
### Function: BBpress Latest Discussions Sidebar Widget
function bbld_widget($args) {
global $table_prefix,$wpdb;
$bbld_template = get_option('bbld_template');
$bbld_option = get_option('bbld_option');
$template_sidebar = str_replace("%BBLD_LIMIT%", $bbld_option['limit'], $bbld_template['widget']);
extract($args);
echo $before_widget;
echo $before_title . $template_sidebar . $after_title;
echo '';
bbld_getside();
echo "
";
echo $after_widget;
if ($bbld_option['donate']) {
bbld_donate();
}
}
### Function: BBpress Latest Discussions Sidebar Widget Control
function bbld_widget_control() {
$bbld_template = get_option('bbld_template');
if ($_POST['bbld_widget_submit']) {
$bbld_template['widget'] = $_POST['bbld_widget_title'];
update_option('bbld_template', $bbld_template);
}
echo '
Allowed Variables: %BBLD_LIMIT%
';
}
### Function: Register BbLD Widget
function bbld_add_widget() {
if (function_exists('register_sidebar_widget')) {
register_sidebar_widget('BbLD Widget','bbld_widget');
register_widget_control('BbLD Widget', 'bbld_widget_control', 400, 300);
register_sidebar_widget('BbLD Forum Widget','bbld_forum_widget');
register_widget_control('BbLD Forum Widget', 'bbld_forum_control', 400, 300);
}
}
### Function: Add BbLD Widget
add_action('init', 'bbld_add_widget');
### Function: Add icon for option page
add_action('admin_head', 'bbld_css');
function bbld_css() {
global $plugin_dir;
echo '
';
}
### Function: BBpress Latest Discussions Option
function wp_bb_option() {
global $wpdb,$BbLD_version,$plugin_dir;
$ori_url = $_SERVER['REQUEST_URI'];
$bbld_template = get_option('bbld_template');
$bbld_option = get_option('bbld_option');
if ($_POST['wpbb_save']) {
check_admin_referer('bbld_save_option');
$bbld_option['url'] = $_POST['bburl'];
$bbld_option['limit'] = $_POST['bblimit'];
$bbld_option['prefix'] = $_POST['bbprefix'];
$bbld_option['trim'] = $_POST['bbslimit'];
$bbld_option['exdb'] = $_POST['use_outdb'];
$bbld_option['dbuser'] = $_POST['bbuser'];
$bbld_option['dbpass'] = $_POST['bbpass'];
$bbld_option['dbname'] = $_POST['bbname'];
$bbld_option['dbhost'] = $_POST['bbhost'];
$bbld_option['exclude'] = $_POST['wpbb_exclude'];
$bbld_option['donate'] = $_POST['bbld_donate'];
$bbld_option['share'] = $_POST['bbld_share'];
$bbld_option['slug'] = $_POST['bbld_permalink'];
$bbld_option['utf8'] = $_POST['bbld_utf8'];
$bbld_option['9.0.4'] = $_POST['bbld_backward'];
update_option('bbld_option', $bbld_option);
$update_msg = "BBpress Latest Discussions options saved successfully.
";
}
if ($_POST['wpbb_save_template']) {
check_admin_referer('bbld_save_template');
$bbld_template['header'] = $_POST['bbld_postpage_header'];
$bbld_template['body'] = $_POST['bbld_postpage_body'];
$bbld_template['footer'] = $_POST['bbld_postpage_footer'];
$bbld_template['sidebar'] = $_POST['bbld_sidebar_title'];
$bbld_template['sidedisplay'] = $_POST['bbld_sidebar_display'];
$bbld_template['forum_norm_head'] = $_POST['bbld_sidebar_forum_title'];
$bbld_template['forumwidget'] = $_POST['bbld_forum_sidebar_display'];
$bbld_template['forum_header'] = $_POST['bbld_forum_postpage_header'];
$bbld_template['forum_body'] = $_POST['bbld_forum_postpage_body'];
$bbld_template['forum_footer'] = $_POST['bbld_forum_postpage_footer'];
update_option('bbld_template', $bbld_template);
$update_msg = "BBpress Latest Discussions templates saved successfully.
";
}
?>

If you like my work. Please donate a link back.
"; } ?>