Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 03:09 pm EDT

Geeklog Forums

New Plugin For Classified Ads


Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

I've been using Michael De La Rue's Classifads script to provide classified ads on one of my sites for some time now. Then I thought that this would also make a nice plugin for Geeklog. So I hacked on it long enough until in gave up and integrated nicely into Geeklog.

Please note that this is my first plugin and the integration is not as complete yet, as one might wish. Let me know what you think about it.

The feature list of this plugin is almost identical to the original script by Michael De La Rue:

  • Any number of easily configurable categories
  • Posters choose how many weeks to display their ad for.
  • A "new listings" front page with a drop-down selection of categories to choose from.
  • The script uses a combination of IP logging and cookies, so that if visitors have either a static IP address or cookies enabled, they can alter their ad without having to remember a password. Any ads posted by the visitor are listed with an "alter it" and "delete it" button beneath them.
  • If an email address / url is given, the listing will include an EMAIL / SITE link at the bottom. If not, only the Title - Author & Description are shown.
  • The script automatically erases expired ads from the database.

Additional features, specific to the Geeklog plugin:

  • easy install (you have to copy some files manually, then call an install script that does the rest)
  • available in two languages (English and German)

Download here (21 KCool

bye, Dirk

 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

Okay, the first issues have come up (thanks to toad for the quick feedback). It seems my version of PHP is a bit more fault-tolerant than others ...

If you get "undeclared function" errors, check public_html/index.php and public_html/updata.php and remove the dollar signs from these lines:

echo $COM_endBlock();
echo $COM_siteFooter();

While you're at it, add the following line in public_html/index.php:

$i = "0";
$posti = array (); // this is the line to add
while($ad = mysql_fetch_assoc($query)) {

(that's lines 57-59).

Of course, you could instead just download the updated tarball from the URL provided in the original story.

Sorry about that.

bye, Dirk

 Quote

Anonymous

Anonymous
Good work on this Dirk. I noticed on the submissions that if a user entered a website address without the http:// prefix, like www.usersite.com that my hosted server will for some reason bork the url that is given to the clickable link in the ad. On my site if you dont use the http:// the clickable link url is http://mysite.com/path/to/classifads/. I put a small reminder to users on the submit form this way, <from /public_html/classifads/index.php approx line 108> <tr><td><? echo $LANG_CLADS['adsite']; ?> (http://..) :</td><td> For sure this is not necessary, but it always helps to help your users, plus it takes care of the "Well, why didn't you tell me?" toad.
 Quote

Status: offline

squatty

Forum User
Full Member
Registered: 01/21/02
Posts: 269
Nice work on the classifieds. How about adding a PHP block that would display the most recent posts? I'm working on it myself. I'll post it on GL once all the bugs are worked out.
In a world without walls and fences, who needs Windows and Gates?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

Sounds like a good idea. We have these hints in Geeklog whenever you can enter a URL, so we should have them in the plugins, too. I will add this in the next release of the plugin.

BTW, you might want to add this in updata.php, too.

bye, Dirk

 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

Thanks, squatty. That will make a nice addition to the plugin and make it integrate further into Geeklog. It should be relatively easy to pull the necessary code from public_html/index.php. Let me know how you get on with it.

bye, Dirk

 Quote

Status: offline

squatty

Forum User
Full Member
Registered: 01/21/02
Posts: 269
I just put the finishing touches on the PHP block. It's a bit rough around the edges but I think most GL site owners will find it of value.

I created a separate php file named display_ads.php. You can view the source code here. Note, the select statement will ONLY display ads submitted within the last 48 hours (at least that's what it's supposed to do Smile

To deploy the block, complete the following:

  • Download the display_adds.php and save it to your /public_html/classifads directory
  • Add the following to lib-custom.php:
  • function phpblock_classifieds()
    {
    global $_CONF;
    $path = $_CONF['path_html'] . "classifads";
    include_once($path . "/display_ads.php");
    $display = getads();
    return $display;
    }

    You will also notice that I added two links at the bottom of the block. The submit link goes to an additional page I created. I removed the submit logic from the original index.php. This was just a preference of mine. You can see my version of the plug-in at http://www.squatty.com.

    Thanks,
    Squatty


    In a world without walls and fences, who needs Windows and Gates?
     Quote

    Status: offline

    Dirk

    Site Admin
    Admin
    Registered: 01/12/02
    Posts: 13073
    Location:Stuttgart, Germany

    Thanks, squatty! I had to hack it a bit to get it working, though. But it sure is as nice addition to the plugin, so I will add something like this to the next version of the plugin. I also borrowed your "Fields in bold are required" line, if you don't mind ;-)

    bye, Dirk

     Quote

    toad

    Anonymous
    squatty, had to add, global $_CONF; in function getads{} to get rid of two Warning: Failed opening 'plugins/classifads/classifads.cfg' for inclusion (include_path='./') without it. but still get Warning: Cannot add header information - headers already sent by (output started at lib-common.php(405) : eval()'d code:10) in path/to//geeklog/public_html/classifads/display_ads.php on line 29 but the block does show any ideas? toad
     Quote

    Status: offline

    squatty

    Forum User
    Full Member
    Registered: 01/21/02
    Posts: 269
    Thanks for the heads up on the $_CONF. I made the update on the phps file. As for the headers already sent warning, I assume this is a being generated by lib-custom.php. I'm reading from the HTTP headers to find the Remote IP address of the user. I don't seem to have the issue on my site. What versions are you running. Apache, PHP, Geeklog, ect. Not that I would know how to fix it, just curios. Let me know if you find any additional bugs. This was a quick fix on my part. I'm sure there's plenty of other issues to be found Smile
    In a world without walls and fences, who needs Windows and Gates?
     Quote

    toad

    Anonymous
    I think it may have something to do with setcookie($_CA_CONF['cookie'], "$rip", $exp); after the headers have been sent but what I did in the meantime is borrow error_reporting(0); from Dirks' index.php (maybe it was there for a reason?) and now the message isn't plastered on my page. Don't know exactly what the effect of that is right now, but I guess when the thing progesses it will be fixed.
     Quote

    toad

    Anonymous
    I thought a bit and came up with this, why are you messing with the cookies thing in a block that just displays ads already placed? Couldn't think of a reason so I did this, // if(isset($HTTP_COOKIE_VARS[$_CA_CONF['cookie']])) { // $rip = $HTTP_COOKIE_VARS[$_CA_CONF['cookie']]; // } // else { // $rip = $REMOTE_ADDR; // $exp = time() + 3600 * 24 * 7; // setcookie($_CA_CONF['cookie'], "$rip", $exp); // } I also tossed the error_reporting(0) I had put in and now the block works fine.
     Quote

    Status: offline

    squatty

    Forum User
    Full Member
    Registered: 01/21/02
    Posts: 269
    The cookies are in the script in order to display the "Alter it" and "Delete it" buttons. The plug-in uses similar logic to allow the ad poster the ability to update/delete a previously submitted ad. I wasn’t going to include this at first but, after further review I thought why not? Ideally, all submission should go through the GL submission process. Meaning, the site admin would approve ads so cookies would become obsolete. Just my 2 cents. This might be in the works for future releases. Dirk did mention adding more GL integration?
    In a world without walls and fences, who needs Windows and Gates?
     Quote

    toad

    Anonymous
    The block itself does not do the submit, alter, delete, you have linked that out to the submit, index page you made. So the cookie stuff is not required for the display block, at least not mine. :^) But I'm using the block code, so thanks! Originally I just had a normal block called Classifieds with just a link to the index.php. Thanks to you the block now has the listing along with the link.
     Quote

    toad

    Anonymous
    I just relooked at your code and see that the alter & submit buttons are also in the block, you don't see them unless you placed an ad.
     Quote

    Status: offline

    squatty

    Forum User
    Full Member
    Registered: 01/21/02
    Posts: 269
    Yep, that's why the cookie is set.
    In a world without walls and fences, who needs Windows and Gates?
     Quote

    toad

    Anonymous
    setting that cookie from within the ads block is what causes the error on my system. with the ads block code out of the box I get the error, with only the set cookie line commented out the error is gone. I think that it has to do with the headers for the page having been sent before the block code wants to set the cookie. So doing cookies from blocks is kinda tricky. I'm not a pro, I'm just speculating on what it seems to me.
     Quote

    Status: offline

    squatty

    Forum User
    Full Member
    Registered: 01/21/02
    Posts: 269
    I made a small update to the PHP block. I added a condition to return a "No new ads" in the event of the query result set returning no rows. You can get the update here.
    In a world without walls and fences, who needs Windows and Gates?
     Quote

    All times are EDT. The time is now 03:09 pm.

    • Normal Topic
    • Sticky Topic
    • Locked Topic
    • New Post
    • Sticky Topic W/ New Post
    • Locked Topic W/ New Post
    •  View Anonymous Posts
    •  Able to post
    •  Filtered HTML Allowed
    •  Censored Content