Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
EXPERTS: Running the Postnuke API outside of Postnuke?
  • Posted: 18.07.2004, 01:37
     
    Grant29
    rank:
    Helper Helper
    registered:
     July 2003
    Status:
    offline
    last visit:
    11.04.06
    Posts:
    261
    Hi,

    I am experimenting with trying to run some PHP code with the PostNuke API outside of the PostNuke framework, but on a PostNuke site.

    The reason for doing this is that I would like to try creating some background tasks that I can run via a cron job. Examples would be generating a lists of stats every day and having it automatically email them to me on my cell phone while I am out of town.

    This is a snippet of code where I am trying to get the number of visitors for the day from the database. It's kinda messy, but I'm just trying some proof of concept ideas:

    Code

    <?php

    // Include these files....
    include '/var/www/html/postnuke/includes/pnAPI.php';

    // start PN
    pnInit();

    list($dbconn) = pnDBGetConn();

    //Today
    $toddate = date("dmY");
    $column = &$pntable['stats_date_column'];
    $toddb=$dbconn->Execute("SELECT $column[hits] as hits FROM $pntable[stats_date] WHERE $column[date]='".pnVarPrepForStore($toddate)."'");
    if(!$toddb->EOF) {
      list($valtoday)=$toddb->fields;
    } else {
      $valtoday=0;
    }

    echo "Number of todays visitors: $valtoday<br>";
    ?>


    When I execute this, I get this error message in my browser:

    Quote


    Fatal error: Call to undefined function: adonewconnection() in /var/www/html/postnuke/includes/pnAPI.php on line 488

    Ultimately I wouldn't run this script via a brower, but through the PHP command line interpreter.

    Any PHP/Postnuke experts out there that can help?

    Thanks,
    Grant

    --
    Retail Retreat
    http://www.retailretreat.com
  • Posted: 18.07.2004, 05:04
     
    Lilltiger
    rank:
    Freshman Freshman
    registered:
     July 2004
    Status:
    offline
    last visit:
    25.07.04
    Posts:
    24

    Code

    function &NewADOConnection($db='')


    Is defined in: pnadodb/adodb.inc.php
    Try to include this file..
  • Posted: 18.07.2004, 13:00
     
    r3ap3r
    rank:
    Helper Helper
    registered:
     January 2004
    Status:
    offline
    last visit:
    22.02.08
    Posts:
    381
    The problem is that the current implementation of the API assumes that the files that will be calling it are located one directory below the API itself (in the root of the PostNuke directory). It then looks for adodb in the postnuke_root/pnadodb directory. The only way to currently get your script to work with the API is to put it in the postnuke_root directory. In your case that would be /var/www/html/postnuke.

    Hope that helps,
    -Chris
  • Posted: 22.07.2004, 06:30
     
    Grant29
    rank:
    Helper Helper
    registered:
     July 2003
    Status:
    offline
    last visit:
    11.04.06
    Posts:
    261
    Thanks Chris. I'll give that a shot. I was beginning to figure that out after I checked out the backend.php script. It uses the PostNuke API, but I didn't know that I had to have it in the root module.

    Thanks,
    Grant

    --
    Retail Retreat
    http://www.retailretreat.com
  • Posted: 22.07.2004, 17:31
     
    rank:
    Professional Professional
    registered:
     April 2002
    Status:
    offline
    last visit:
    24.11.08
    Posts:
    716
    You can change your directory to the PostNuke root directory. This is exactly how postnuke_frame works. See here.

    You need a little more work, like "repairing" pnGetBaseURL function, correcting the image links for the theme etc.

    In your case, using postnuke_frame, the script would be

    Code

    <?php
    include_once ('/path/to/postnuke/postnuke_frame.php');
    $postnuke_frame = new postnuke_frame();

    list($dbconn) = pnDBGetConn();

    //Today
    $toddate = date("dmY");
    $column = &$pntable['stats_date_column'];
    $toddb=$dbconn->Execute("SELECT $column[hits] as hits FROM $pntable[stats_date] WHERE $column[date]='".pnVarPrepForStore($toddate)."'");
    if(!$toddb->EOF) {
      list($valtoday)=$toddb->fields;
    } else {
      $valtoday=0;
    }


    echo $postnuke_frame->header;
    echo "Number of todays visitors: $valtoday<br>";
    echo $postnuke_frame->footer;
    ?>


    HTH,

    Jörg

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula