[1.8] Show first post (mod)
#1
Show first post plugin for MyBB 1.8.x
This plugin shows first post on each thread page.

This is modification of plugin Show First Post [1.4] created by Jasiu & krig. Since authors of this plugin is not active anymore and plugin have no any license, I made a little modification for compability with 1.8.x, and post it to the public.

Warning: I'm not a PHP developer and my madskillz in PHP are poor. But I'll try to learn quickly as I can.
Sorry for grammar and other mistakes, English is not my native language.

# Changes compare to original plugin:
- fixed template insert incompabilty with MyBB 1.8.x
- fixed template look and feel to match default MyBB 1.8.x view
- fixed general incompabilty with MyBB 1.8.x
- moderator options (pin/unpin) are working now

# Known issues:
- pinned post always have PID of the last post in thread
- redirect message have no language strings
- incorrect settings state after disable/enable plugin (always show default settings state)

# TODO
- uninstallation feature with correct deletion of all plugin settings from DB
- proper language support (for now, plugin uses single lang file and insert ACP settings / redirect messages strings direct in template) for ACP, redirect message
- query optimization?

# Download:
Version 1.4.5 in attachment.

My main questions are:
- how to implement correct language support, with separate ACP and general lang files?
- how to implement correct uninstallation process?
- what about license? I want this plugin to be available for all without any limitations.

I'll be appreciate any help in development!


Attached Files
.zip   show_first_post_for_mybb18.zip (Size: 3.55 KB / Downloads: 183)
English is not my native language, so, sorry for any mistakes which I will do for sure.
Reply
#2
Hi, thanx for your work on the plugin!

With PHP 7.2 there is a warning when global_first_post template is evaluated:

<error>
 <dateline>1531610597</dateline>
 <script>inc/plugins/show_first_post.php(147) : eval()'d code</script>
 <line>2</line>
 <type>2</type>
 <friendly_type>Warning</friendly_type>
 <message>Use of undefined constant borderwidth - assumed 'borderwidth' (this will throw an Error in a future version of PHP)</message>
</error>

<error>
 <dateline>1531610597</dateline>
 <script>inc/plugins/show_first_post.php(147) : eval()'d code</script>
 <line>2</line>
 <type>2</type>
 <friendly_type>Warning</friendly_type>
 <message>Use of undefined constant tablespace - assumed 'tablespace' (this will throw an Error in a future version of PHP)</message>
</error>

<error>
 <dateline>1531610597</dateline>
 <script>inc/plugins/show_first_post.php(147) : eval()'d code</script>
 <line>5</line>
 <type>2</type>
 <friendly_type>Warning</friendly_type>
 <message>Use of undefined constant threadprefix - assumed 'threadprefix' (this will throw an Error in a future version of PHP)</message>
</error>

<error>
 <dateline>1531610597</dateline>
 <script>inc/plugins/show_first_post.php(147) : eval()'d code</script>
 <line>5</line>
 <type>2</type>
 <friendly_type>Warning</friendly_type>
 <message>Use of undefined constant subject - assumed 'subject' (this will throw an Error in a future version of PHP)</message>
</error>


The problem is that in the template:

$theme[borderwidth]

should correctly be:

$theme['borderwidth']

To fix this, in the plugin file I changed the $fp_template array like this:

$template_text = "<table border=\"0\" cellspacing=\"{\$theme['borderwidth']}\" cellpadding=\"{\$theme['tablespace']}\" class=\"tborder tfixed clear\">
 <tr>
 <td class=\"thead\">
 <div><strong>{\$lang->first_post} - {\$thread['threadprefix']}{\$thread['subject']}</strong></div>
 </td>
 </tr>
 <tr>
 <td id=\"posts_container\">
 <div id=\"posts\">
 {\$posts}
 </div>
 </td>
 </tr>
 </table>
 <br />";

 $fp_template = array (
 "title" => "global_first_post",
 "template" => $db->escape_string($template_text),
 "sid" => -1,
 "version" => 122,
 "status" => "",
 "dateline" => time(),);


Here is also some code to handle complete Uninstall:

function show_first_post_uninstall()
{
	global $mybb, $db;
	
	if($mybb->request_method != 'post')
	{
		global $page, $lang;
		
		//TODO: add inc/languages/english/admin/config_show_first_post.php
		//$lang->load('config_show_first_post');
		//$page->output_confirm_action('index.php?module=config-plugins&action=deactivate&uninstall=1&plugin=show_first_post', $lang->sfp_uninstall_message, $lang->sfp_uninstall);
		
		$page->output_confirm_action('index.php?module=config-plugins&action=deactivate&uninstall=1&plugin=show_first_post', "Each thread has a setting whether first post is pinned. Do you wish to remove all these settings?", "Uninstall First Post MOD");
	}
	
	if(!isset($mybb->input['no']))
	{
		if($db->field_exists('fix_first_post', 'threads'))
		{
			$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP column `fix_first_post`"); 
			//$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD `fix_first_post_test` TINYINT(1)");
		}
	}
}

function show_first_post_is_installed()
{
	global $db;	
	
	if($db->field_exists('fix_first_post', 'threads'))
	{
		return true;
	}
	return false;
}


You can consider adding the plugin here: https://community.mybb.com/mods.php
Reply
#3
I created a project page for this plugin so that it is easier to find and maintain. If anyone would like to collaborate, please let me know.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)