Version: , by (Guest)
Developer Last Online: Jan 1970
Version: Unknown
Rating:
Released: 06-18-2001
Last Update: Never
Installs: 3
No support by the author.
Another quick, but kick-arse hack. We have a home-made content management system (actually, a beta tool see incursio.com for more info - product is called Editio). At any rate, it allows staff or community members to create online articles. Once articles are published, I wanted a way to automatically link them into our forums, so people could start a discussion, or join a discussion already in progress about that particular article. Yahoo! does this with news events as well.
At any rate, perl script. chmod 755, I call it discuss_link.cgi. It should be invoked via SSI. Under Apache:
In the link above, plug in your forum number (forumid column in VB), and the title of the article. The title will be used as the title of the post. If a post exists in the passed forum with that title, a link to "Join the conversation" will be emitted. Otherwise, you get a link called "Start a conversation". You get the picture.
Our content management system (through its plugin concept) allows us to have stuff like this embedded within each article - you could cobble up something similar in your own system with a little effort.
Code:
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
use DBI;
#Require the cgi library
require '/opt/web/cgi-bin/cgi-lib.pl';
&ReadParse(*input);
# Grab fields
$topic = $input{'topic'};
$forum = $input{'forum'};
# Does the forum/topic combo exist?
# Connect to mySQL
$dbh = DBI->connect( "DBI:mysql:vbulletin", "id", "password");
if ( !defined $dbh ) {
print "<LI>Cannot connect to mySQL server: $DBI::errstr\n";
}
# Grab the forum name
$q = "SELECT title FROM forum WHERE forum = $forum";
$sth = $dbh->prepare($q);
$sth->execute;
@result = $sth->fetchrow_array;
$forum_name = $result[0];
$sth->finish;
$quoted_title = $dbh->quote($topic);
$q = "SELECT threadid FROM thread WHERE forumid = $forum AND title = $quoted_title";
$sth = $dbh->prepare($q);
$sth->execute;
@result = $sth->fetchrow_array;
$threadid = $result[0];
$sth->finish;
# Prep for linking
$topic =~ tr/ /+/;
if( $threadid <= 0 ) {
print "<A HREF=http://www.mysite.com/forums/newthread.php?s=&action=newthread&forumid=$forum&subject=$topic>Start a Conversation!</A>";
exit(1);
}
print ("<A HREF=http://www.mysite.com/forums/showthread.php?s=&threadid=$threadid>Join the Conversation!</A>");
exit;
Cheers.
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
The #include will only work if your Apache web server supports server-side includes (SSI). With regard to the PHP version that akiy posted - you just have to include it in using PHPs include syntax:
PHP Code:
<? include "/path/to/your/script/whatever.php"; ?>
OK, that worked, but now I recieve this error where the link should be.
Warning: open_basedir restriction in effect. File is in wrong directory in /home/sites/site207/web/browse.php on line 306
Warning: Failed opening '/discussion_link.php' for inclusion (include_path='.:..:/usr/local/lib/php') in /home/sites/site207/web/browse.php on line 306
The usr/local/lib/php would be necessary? I wasn't aware php required a bin.. but I'm a novice, so eh.. is there any quick fix to this?
I would guess your include path is not the full path - if your on a shared server this is likely to be the case - you may need to add sometheing like www/public_html/ infront of your path. You cant set a .htaccess to stop you having to do this repetitively (which I have done) - but don't ask me how off my head. - do a search.
Warning: open_basedir restriction in effect. File is in wrong directory in /home/sites/site207/web/get.php on line 144
Warning: Failed opening 'home/sites/site207/web/discussion_link.php' for inclusion (include_path='.:..:/usr/local/lib/php') in /home/sites/site207/web/get.php on line 144
Got this again. Do you think the first "open_basedir" is a setting, perhaps a permissions setting that needs to be configured? I did a google search for this error text, and it appears to be VERY common.