1

(1 replies, posted in PunBB 1.2 show off)

It was awhile ago that I integrated my main website's news posts with punbb.  But recently I took it a step further by fine-tuning my old webcomic's navigation and comic-posting with it as well.

This isn't really a 'show off your website' type deal, more like a 'look at a nifty script i wrote' that ties two sets of files together with punbb's db rather nicely.

Honestly, I'm just giddy that it worked so I want to show other people. =P

anyway...

#!/usr/bin/perl/

# 0) preface
# 1) modules, includes, declare variables
# 2) create db connections
# 3) create an array from all images in the strips dir
# 4) run through each strip in the array
#   a) check for an entry in the html dir, set $newspost to either empty or the contents
#   b) create a topic/post in the forum, set timestamp to date of image (name)
#   c) insert row into snat_strips table

# 1) modules, includes, declare variables
  use strict;
  use DBI;
  require "time.pl";
  my $newspost;
  my $subject;
  my $created;
  my $topic;
  my $post;
  my $myquery;

# 2) create db connection
  my $dbh = DBI->connect('DBI:mysql:this:info', 'is', 'fake') or die "Couldn't connect to database: " . DBI->errstr;
  my $dbh2 = DBI->connect('DBI:mysql:this:info', 'is', 'fake2') or die "Couldn't connect to database: " . DBI->errstr;

# 3) create an array from all images in the strips dir
  my @strips = <strips/*>;
  foreach my $strip (@strips) {
    $strip =~ s/\w+\///;
  }

# 4) run through each strip in the array
  foreach my $strip (@strips) {
    my $date = $strip;
    $date =~ s/\.\w+//;
    $newspost = "http://dev.snatcomic.com/index.php?strip=".$date."\n\n";
    if (-e "news/".$date.".html") {
      # news file exists, so open file and set $newspost to contents
      open (TEMP, "<" . 'news/'.$date.'.html') or die "Couldn't open old file: $!";
      while (my $line = <TEMP>) {
        $line =~ s/<br\s*\/>//;
        $newspost .= $line;
      }
      close TEMP;
    } else {
      # nothing found
      $newspost .= "";
    }
    
    # gonna need some variables for the field values.
    # first, $subject will be the strip date
    my $subject = $date;
    
    # second, $created will be the timestamp converted from the file name
    my $created = convertTime($date);
  
    # chomp $newspost
    chomp($newspost);
  
    # add a new topic
    $myquery = "INSERT INTO foo_pun_topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES (?, ?, ?, ?, ?, ?)";
    my $sth = $dbh->prepare($myquery) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute('I like pie', $subject, $created, $created, 'I like pie', '4') or die "Couldn't execute statement: " . $sth->errstr;
 
    # get id of topic created
    $topic = $sth->{'mysql_insertid'};

    # add a new post
    $myquery = "INSERT INTO foo_pun_posts (poster, poster_id, message, posted, topic_id) VALUES (?, ?, ?, ?, ?)";
    my $sth = $dbh->prepare($myquery) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute('I like pie', '3', $newspost, $created, $topic) or die "Couldn't execute statement: " . $sth->errstr;

    # get id of post just created
    $post = $sth->{'mysql_insertid'};

    # update topic with recent post info
    $myquery = "UPDATE foo_pun_topics SET last_post_id = $post WHERE id = $topic";
    my $sth = $dbh->prepare($myquery) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute() or die "Couldn't execute statement: " . $sth->errstr;

    # insert row into snat_strips
    $myquery = "INSERT INTO snat_strips (strip_id, filename, thread_id) VALUES (?, ?, ?)";
    my $sth = $dbh2->prepare($myquery) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute($date, $strip, $topic) or die "Couldn't execute statement: " . $sth->errstr;
  }

The result?  check out the last page of my (dev) forum sub-section for the webcomic:

http://dev.foohonpie.net/forums/viewfor … =4&p=5

Yep, that's posts seemingly written 3 years ago, way before I had ever heard of punbb.  Nifty!

As if that isn't well enough, I've also modded punbb a bit to upload comic strips on the fly via the new topic post page.

On a side-note: I've decided that I don't need wordpress or anything else for any of my projects.  PunBB is going to be the central content management system for all my projects.  Who needs anything else?

A newfound love for perl, and a rediscovered love for punbb.  w00t

[edit]
hmm.... on second glance it seems my timestamp converting is bugged.  oh well, the meat and potatoes of it all works fine still

Well, I'm thinking checkboxes instead of a dropdown.  That way I can choose multiple tags.  I think I'll have to end up hiding it so that my post page doesn't get unnecessarily cluttered.

3

(3 replies, posted in PunBB 1.2 troubleshooting)

w00t, my first useful mod big_smile  now view count only increases if the viewer isn't the post author big_smile

4

(3 replies, posted in PunBB 1.2 troubleshooting)

got it big_smile

i figured it out and deleted the post, but you responded before that yikes

so quick smartehs... so freakin quick >=|

5

(3 replies, posted in PunBB 1.2 troubleshooting)

Is $cur_post['poster_id'] the current post's author's ID?  or the current poster/user's id?  I assumed the former, but this makes me think the latter:

// If the poster is a registered user.
if ($cur_post['poster_id'] > 1)

that implies the current user viewing the topic.

I'm trying to compare the two to eachother and carry out a script if the two are the same, but I'm not sure what I should be using.

[edit]

nevermind, i read it again and pretty sure it's the former.  just got confused for a sec.  feel free to delete this post =P

Well, this is working great so far, but I've come across another issue now.

I'm writing a tagging system for my newsposts.  1 for "Foohon Pie", 2 for "Trout Slap", etc...

I assume what I need now is some sort of javascript to display a list of possible tags when I check the "Newspost?" checkbox.

I've got a good idea on how to write the code, but before I do, I wanted to ask you guys if you know of another way to go about it.  I'd like to keep my stuff free of javascript if I can.

haha, how dumb of me.  i put it in the actual site, not the dev

d'oh!

well, i'd rather not have my db info inside the file itself.  i tried putting:

include('../include/np_config.php');

but then i get this:

Warning: require(../include/np_config.php) [function.require]: failed to open stream: No such file or directory in /home/.gentlegift/dev_fpp/dev.foohonpie.net/forums/post.php on line 295

but i don't see why that's wrong.  post.php is in site/forums/ and np_config.php is in site/include/

alright, well i've just about got this down... there's just one thing.  which is a php/mysql question more than punbb...  but anyway:

how would i go about creating an insert query for a different db than what the current page is using? i see that punbb has $db->query(blah), but the $db itself seems to be calling start_transaction(), and i can't seem to find that

so what do i need to have in place of that?

10

(5 replies, posted in PunBB 1.2 troubleshooting)

yep, that was it big_smile

i lub j00 smartehs

11

(5 replies, posted in PunBB 1.2 troubleshooting)

ok.. here's another one

i upgraded, and i've looked at the files and they're current.  i ran the 12_to_1212_update.php and it still tells me that i'm running the old version

when i try to run it again it tells me that i'm not running a supported version (i take it this means i can't upgrade from 1.2.14 again, makes sense)

any ideas on what's going on?

12

(5 replies, posted in PunBB 1.2 troubleshooting)

YES!  i knew it was there somewhere... i swear i checked the admin page like 4 times too...

*slaps forehead

thanks alot

13

(5 replies, posted in PunBB 1.2 troubleshooting)

i must be blind... or maybe cause i had a beer.  but i can't seem to find out what version of punbb i have installed, and i need to upgrade.

is this hidden away somewhere?  or am i just losing it?

i'd imagine this should be relatively simple, but i'm not quite sure where to start.

my site pulls some posts from my punbb db to use as newsposts on the front page.  this would be simple enough if it was only the punbb stuff i was using, but it also pulls posts from a different forum as well

as it is, i have a db for my site that has a table (we'll call it, fpp_table) which includes topic id's for punbb and the other forum.  but i have no way to automatically insert these topic ids, so I have to manually insert them into the db after i make a post.  this  is obviously a clunky way to handle things.

so what i need to do... is create a new checkbox for when i start a topic (only viewable as admin), something like "use as newspost?", and when it's checked, it runs a seperate chunk of php that inserts the relavent topic data into fpp_table

so how would i go about doing this?

15

(3 replies, posted in PunBB 1.2 discussion)

oh man, i can't believe i didn't see that.  *slaps forehead

thanks, let's hope this works out

16

(3 replies, posted in PunBB 1.2 discussion)

i have my forum here and my website here

the news page of my site pulls any relevant sticky posts created by me and shows them.  what i can't figure out is how to go about converting the unix timestamps in the post table into readable dates in the way that punbb does it

the only thing in can find in viewtopic.php is format_time() and i can't seem to find where that function is defined.

17

(3 replies, posted in PunBB 1.2 discussion)

/me slaps elbekko

don't listen to that guy, he's lying to you

evil... he's pure freakin evil

19

(1 replies, posted in PunBB 1.2 show off)

I can't bring myself to bother with a new skin, I like the default one too much. =P

20

(6 replies, posted in PunBB 1.2 discussion)

I know from experience that sometimes hard work can go without any thanks, and that sometimes a good comment can just make ya feel good.

So here's my good comment for Rickard, and any of you guys who've helped with the developement of these wonderful forums.  Smartys recently convinced me to give up phpBB and try something new, and I couldn't be happier with the decision.  These forums really are great, and simple, and the features that you do have are done so well that I can't even put it into words (specifically, the way profiles are handled... beautifully done).

So again, thanks.  I highly doubt I will go back to phpBB, they were great for awhile... but punBB has my loyalty now. =P