MyBB Community Forums

Full Version: Get PID & TID when edit post
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I need to get the post id and thread id when I modify a post and do an output with them. How can I do this?

I need to check if PID == TID, so if the post it the first of thread (then the thread) and replace a code in editpost template with another..
TID == PID does not mean is the first post. what hook are you using and we can then tell you what variables are available
I'm using editpost_start and newthread_start hooks, however there's a way to enable post edit to other users specified? Without change PHP code in the 'subfiles'
Take a look at this plugin of mine, you'll know about editing post and also new thread:

http://mods.mybb.com/view/invite-only-threads
there are first post checks throughout the editpost.php file, so what part of it are you needing to modify based on the first post? are you modifying the editpost page or working on data after an submit or delete command has been submitted?
(2012-12-06, 02:17 PM)crazy4cs Wrote: [ -> ]Take a look at this plugin of mine, you'll know about editing post and also new thread:

http://mods.mybb.com/view/invite-only-threads

Thanks, but I don' t know why eval doesn' t work. There' s the template in the database, there' s the var giverights in the template "newthread" and "editpost", but nothing happens. Complete code:

<?php
/**
 * MyBB 1.6
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/eula.html
 *
 *
 */

if(!defined("IN_MYBB")) {
    die("Non si pu&ograve; utilizzare questo file direttamente.<br /><br />assicurati che IN_MYBB sia definita.");
}

$plugins->add_hook("newthread_start", "Give_Rights_newthread_display");
$plugins->add_hook("editpost_action_start", "Give_Rights_editpost_display");

function Give_Rights_info()
{
    return array(
        "name"        => "Dai diritti",
        "description" => "Permetti la modifica del tuo thread ai tuoi amici!",
        "website"     => "http://www.slimmer.it",
        "author"      => "Kaito",
        "authorsite"  => "http://www.slimmer.it",
        "version"     => "1.0",
    );
}

function Give_Rights_activate() {
	global $mybb, $db;
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("newthread", '#{\$modoptions}#', "{\$modoptions}{\$giverights}");
	find_replace_templatesets("editpost", '#{\$disablesmilies}#', "{\$disablesmilies}{\$giverights}");
	$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD urights TEXT NOT NULL");
	$template1 = array(
			"title"		=> "giverights",
			"template"	=> '<tr>
	<td class="trow2" width="20%"><strong>Diritti</strong><br /><span class="smalltext">Separa gli username degli utenti a cui vuoi dare i diritti con una virgola</span></td>
	<td class="trow2"><input type="text" class="textbox" name="usersrights" size="40" /></td>
</tr>',
			"sid"		=> -1
	);
	$db->insert_query("templates", $template1);
	rebuild_settings();
}

function Give_Rights_deactivate() {
	global $mybb, $db;
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("newthread", '#'.preg_quote('{$giverights}').'#', '',0);
	find_replace_templatesets("editpost", '#'.preg_quote('{$giverights}').'#', '',0);
	$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP `urights`");
	$db->delete_query("templates","title='giverights'");
}

function Give_Rights_newthread_display() {
    global $templates;
	$temprights = $templates->get("giverights");
	eval("\$giverights = \"$temprights\";");
}

function Give_Rights_editpost_display() {
    global $mybb, $templates, $db, $usersrights, $checked, $post, $lang;	
	$query = $db->query("SELECT tid, urights, firstpost FROM ".TABLE_PREFIX."threads where tid='".$post['tid']."'");
	
	while($do = $db->fetch_array($query))
	{
	$usersrights = $do['urights'];
	$GLOBALS['usersrights'] = $usersrights;
	$firstpost = $do['firstpost'];
	}
	
	if($firstpost == $post['pid']) {
		$temprights = $templates->get("giverights");
		eval("\$giverights = \"$temprights\";");
    }
}	


?>
change both

    $temprights = $templates->get("giverights");
    eval("\$giverights = \"$temprights\";");

to

    eval("\$giverights = \".$templates->get("giverights")."\";");
Change to what pavemen said. You're mixing my code and your code. The evaluate one, take it from my plugin, it's like what pavemen said.

And you probably just slapped the major of my plugin's function there. There are several globals which are defined which you probably won't need. So use and edit it as per your liking.
(2012-12-06, 05:00 PM)pavemen Wrote: [ -> ]change both

    $temprights = $templates->get("giverights");
    eval("\$giverights = \"$temprights\";");

to

    eval("\$giverights = \".$templates->get("giverights")."\";");

There's no difference, 'cause before I inserted this:

eval("\$giverights = \"".$templates->get("giverights")."\";");

@crazy4cs I included $db, $mybb, $templates but nothing happens. I tried to install your plugins, and nothing happens. Maybe I need to reinstall the board?

New codes:

<?php
/**
 * MyBB 1.6
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/eula.html
 *
 *
 */

if(!defined("IN_MYBB")) {
    die("Non si pu&ograve; utilizzare questo file direttamente.<br /><br />assicurati che IN_MYBB sia definita.");
}

$plugins->add_hook("newthread_start", "give_rights_newthread_display");
$plugins->add_hook('datahandler_post_validate_thread', 'give_rights_newthread_validate');
$plugins->add_hook("datahandler_post_insert_thread", "give_rights_newthread_action");
$plugins->add_hook("editpost_action_start", "give_rights_editpost_display");
$plugins->add_hook("editpost_do_editpost_start", "give_rights_editpost_action");
$plugins->add_hook("showthread_start", "give_rights_check");
$plugins->add_hook("newreply_start", "give_rights_reply_check");

function give_rights_info() {
    return array(
        "name"            => "Dai diritti",
        "description"    => "Permetti ad altri utenti di modificare il tuo thread",
        "website"        => "http://www.slimmer.it",
        "version"        => "1.0",
        "author"        => "Kaito",
        "authorsite"    => "http://www.slimmer.it",
        "compatibility"  => "*",
    );
}

function give_rights_install() {
	global $db;
	$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD urights TEXT NOT NULL");
	$template1 = array(
		"title"		=> "giverights",
		"template"	=> '<tr>
<td class=\"trow2\" valign=\"top\"><strong>Test</strong></td>
<td class=\"trow2\"><span class=\"smalltext\">
<label><input type=\"checkbox\" class=\"checkbox\" name=\"inviteonlycheck\" value=\"1\" {$checked}/>&nbsp;Prova</label><br />
Desc
</span></td>
</tr>',
		"sid"		=> -1
	);
	$db->insert_query("templates", $template1);
}

function give_rights_is_installed() {
	global $db;	
	if($db->field_exists("urights", "threads"))	{
		return true;
	}
	return false;
}

function give_rights_activate() {
    global $mybb;
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("newthread", '#{\$modoptions}#', "{\$modoptions}{\$gr}");
	find_replace_templatesets("editpost", '#{\$disablesmilies}#', "{\$disablesmilies}{\$gr}");

}

function give_rights_deactivate() {
    global $mybb;
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("newthread", '#'.preg_quote('{$gr}').'#', '',0);
	find_replace_templatesets("editpost", '#'.preg_quote('{$gr}').'#', '',0);

}

function give_rights_uninstall() {
    global $db;
	$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP `urights`");	
	$db->delete_query("templates","title = 'giverights'");
}

//Eval when creating new thread

function give_rights_newthread_display()
{
    global $mybb, $templates, $iot, $lang;
	eval("\$gr = \"".$templates->get("giverights")."\";");
}

function give_rights_newthread_validate(&$dh) {
    global $mybb;
} 

function give_rights_newthread_action(&$dh) {
    global $mybb, $lang, $db;			
}

//OP is editing his thread

function give_rights_editpost_display() {
    global $mybb, $templates, $iot, $db, $existinguids, $checked, $post, $lang;	
	$query = $db->query("SELECT tid, urights, firstpost FROM ".TABLE_PREFIX."threads where tid='".$post['tid']."'");
	while($do = $db->fetch_array($query)) {
		$firstpost = $do['firstpost'];
	}
	if($firstpost == $post['pid']) {
		eval("\$gr = \"".$templates->get("giverights")."\";");
    }
}	

function give_rights_editpost_action() {
    global $mybb, $lang, $thread, $db, $post;		
}

//We now have completed major tasking, time for action

function give_rights_check() {
	global $mybb, $lang, $thread;
}

function give_rights_reply_check() {
	global $mybb, $lang, $thread;
}
?>
My plugin works fine. As said previously, you're doing C&P of my plugin code which is intended for something different and you're merging two things together. I told you to take idea from that plugin of mine and even code, but now you're confused merging two together.

What are you exactly trying to achieve?
Pages: 1 2