PDA

View Full Version : Get postid # in a thread?


Ian Cunningham
03-27-2002, 05:45 PM
Hi,

I have a news catagory in one of my forums, with about 50% of the posts containing attached images... (see http://www.pcreview.co.uk/showthread.php?s=&threadid=154 for example)

I am currently attaching the image, then editing the post and adding [ IMG ] attachment.php?s=&postid=xxx [/ IMG ] in the post, because I now know the postid #

I cant just tell VB to show the image in the post in the news options, because I need it in various places in the post

Is there any way to modify VB so that I can add a string in a post, and when it is posted, it appears as the attached image?

Thanks, Ian

xware
03-27-2002, 06:44 PM
[ IMG ] attachment.php?s=&postid=$post[postid][/ IMG ]

Ian Cunningham
03-27-2002, 06:49 PM
I have just posted a test reply, with that in... but it doesnt work, it shows the URL of the broken image as attachment.php?s=&postid=$post[postid]

So theoretically, just posting $post [postid] should give this thread a number:

$post[postid]

xware
03-27-2002, 07:05 PM
Sorry.
Maybe I miss your meaning.
You need edit the every postid=xxx to some acture postid.
There xxx is the attach's postid.

Ian Cunningham
03-27-2002, 07:32 PM
Is there any code I can stick in the post that will automatially do that?

xware
03-27-2002, 07:42 PM
Oh, I think you can use usercp to change options:
Show image attachments and [img] code in Posts?
set it to yes.
Then the attchimage will display.

Ian Cunningham
03-27-2002, 07:49 PM
If I do that, I cant select where the image is though?

What I really need is to somehow replace "{postid}" with the actual post ID?

Admin
03-28-2002, 08:12 AM
You can try this. In functions.php replace:
//smilies
if($dosmilies) {
with:
global $post;
$bbcode = str_replace('{postid}', $post['postid'], $bbcode);
//smilies
if($dosmilies) {

Ian Cunningham
03-28-2002, 10:48 AM
Thanks FireFly, I'll give that a shot :)

Ian Cunningham
03-28-2002, 12:45 PM
It works! (in part anyway ;))

When I view the thread with showthread.php it works great! But, I'm mainly viewing it via webnews.php, from the PluhNews script, and it doesnt parse {postid} as a number

I've tried including functions.php, but no success :( Any Ideas?

Admin
03-28-2002, 02:27 PM
Ok then stick that line (str_replace(...)) in webnews.php, since you are not passing the post through bbcodeparse().

Ian Cunningham
03-28-2002, 04:20 PM
I still cant get this thing to work, but here's a code snippet if thats any help... where {postid} should appear, it is just blank!


<?php
//PluhNews 1.5 released under GNU GPL Licence version 2.0 (see copying.txt file for more info)
//Set your permissions in your control panel to make sure that only YOU and who you specify can post news. Otherwise, everyone and their dog can register and post in your news forums, thus posting where your news will appear. But for this script to work it's extra magic, be sure your members can reply to your news posts.

require("./newsconfig.php");
require('./admin/config.php');
str_replace('{postid}', $post['postid'], $bbcode);

//scroll down to edit the HTML for the news
//**********************

$newsforums = 47;

//Number of news items to show at once
$newsitems = 12;

//Path to your forums directory (leave out trailing slash)
$forumspath = "/";

//Start the goodies (please do not edit to goodies unless you know what you are doing

//connect
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");

//select database
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");

// create sql statement
$sql = "SELECT threadid, title, forumid, replycount, postusername, postuserid, lastposter, dateline, iconid FROM thread WHERE forumid IN ($newsforums) ORDER BY threadid DESC LIMIT $newsitems";

//execute sql query
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");

if (!$sql_result) {
echo "<p>Could not get record.";
}

while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$title = $row["title"];
$forumid = $row["forumid"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
$iconid = $row["iconid"];
$dateline = $row["dateline"];

//create the second SQL statement to pull the post from the thread it resides in
$sql2 = "SELECT postid, threadid, username, userid, title, dateline, pagetext, iconid FROM post WHERE threadid = \"$threadid\" ORDER BY postid ASC LIMIT 1";

//execute second sql query
$sql_result2 = mysql_query($sql2, $connection) or die ("Could not execute query in second sql statement.");

if (!$sql_result2) {
echo "<p>Could not get record in second statement.";
}

while ($row2 = mysql_fetch_array($sql_result2)) {
$pagetext = $row2["pagetext"];



//gotta convert that damn unix time crap
$dateposted = vbdate("D j M Y, g:i A",$dateline);
//end the goodies

if ($replycount==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}

$bericht=bbcodeparse2($pagetext,"1","1","1","1");
// **********************
//Edit the HTML here (keep in mind that any double quote that is HTML requires a backslash in front of it)


echo "
<a name=\"$threadid\"></a>
<a href=\"showthread.php?s=&threadid=$threadid\"><b>$title</b></a><br>
</center>

<blockquote></a>$bericht</blockquote><center>Posted By <a href=\"member.php?s=&action=getinfo&userid=$postuserid\"><b>$postusername</b></a> at <i>$dateposted</i>
- <a href=\"showthread.php?s=&threadid=$threadid\"><b>$replycount</b> $commenttext</a></center><p><br><br>
";

}
}


//add news search stuff (this is optional - delete if you do not wish to include this, or edit it to meet your needs
echo "<center><a href=\"search.php?s=\">Search the News</a> | <a href=\"forumdisplay.php?s=&forumid=$newsforums\">View All News Posts</a></center>";

//end HTML edit
//**********************

//disconnect
mysql_free_result($sql_result);
mysql_close($connection);
?>

Ian Cunningham
03-29-2002, 04:19 PM
I'm afraid I'm still a php n00b, so I haven't been able to figre this one out still :confused:

Ian Cunningham
03-29-2002, 04:46 PM
I have figured out that that code only makes references to the threads, not the posts...

I think I need something like this in there:


$getpostid=$DB_site->query_first("SELECT postid FROM post WHERE threadid='$threadid'" LIMIT 1);


but I'm really not sure

Admin
03-30-2002, 05:18 AM
Ok replace this:
$pagetext = $row2["pagetext"];
with this:
$pagetext = str_replace('{postid}', $row2['postid'], $row2['pagetext']);
That should do the trick.

Ian Cunningham
03-30-2002, 10:17 AM
FireFly, you're a genius :laugh:

Thankyou! :D

Admin
03-30-2002, 10:20 AM
No problems. :)