vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PHP Plugin Error (https://vborg.vbsupport.ru/showthread.php?t=173522)

enci 03-19-2008 05:33 PM

PHP Plugin Error
 
I am trying to place a php script on my board to track user information such as referer, query string, etc. I created a plugin and placed it in the parse_templates hook location. However, when I activate the plugin and test it, I see these errors in my error_log:

PHP Fatal error: Call to a member function query_read_slave() on a non-object in /path/to/board/includes/functions.php on line 2970

PHP Fatal error: Call to a member function shutdown_query() on a non-object in /path/to/board/showthread.php on line 490

PHP Fatal error: Call to a member function unlock_tables() on a non-object in /path/to/board/includes/functions.php on line 4998

I am pretty sure my php script works because I copied it directly from a working script.

Thanks.

Marco van Herwaarden 03-19-2008 05:38 PM

Please post the plugin code.

enci 03-19-2008 05:51 PM

Code:

$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
$script_parts = preg_split("/\//", preg_replace("/^\//", "", $SCRIPT_NAME));
$thispage = array_pop($script_parts);
$thispage = preg_replace("/.php/", "", $thispage);
$section = "forum";
$campaign = $_SERVER['QUERY_STRING'];

#if page is index page, we want to log page category, so array_pop "index" to get category
#example, if page is /Insurance/index.php, we'll array_pop so name becomes Insurance instead of index
if ($thispage == "index") {
  $thispage = array_pop($script_parts);
  if ($thispage == "") {
      $thispage = "Home";
  }
  $thispage = $thispage."_Index";
}

$name = $thispage;

function email_error($reason) {
  $to = "email@test.com";
  $from = "From: db_error@test.com\r\n";
  $subject = "DB Error in Logs DB";

  $body = "There was an error in the logging function of the forum.  ".$reason;

  mail($to, $subject, $body, "$from");
} #end function email_error

function parse_se ($url) {
  if (stripos($url,"translate.google.com") == TRUE) {
      $engine = "Google Translate BETA";
  } elseif (stripos($url,"google.com") == TRUE) {
      $engine = "Google US";
  } elseif (stripos($url,"google.ca") == TRUE) {
      $engine = "Google Canada";
  } elseif (stripos($url,"google.co.uk") == TRUE) {
      $engine = "Google UK";
  } elseif (stripos($url,"google.com.nz") == TRUE) {
      $engine = "Google New Zealand";
  } elseif (stripos($url,"google.com.mx") == TRUE) {
      $engine = "Google Mexico";
  } elseif (stripos($url,"google.com.do") == TRUE) {
      $engine = "Google DR";
  } elseif (stripos($url,"google.co.at") == TRUE || stripos($url,"google.at") == TRUE) {
      $engine = "Google Germany";
  } elseif (stripos($url,"google.co.it") == TRUE || stripos($url,"google.it") == TRUE) {
      $engine = "Google Italy";
  } elseif (stripos($url,"google.com.tr") == TRUE) {
      $engine = "Google Turkey";
  } elseif (stripos($url,"google.ie") == TRUE) {
      $engine = "Google Ireland";
  } elseif (stripos($url,"dmoz.org") == TRUE) {
      $engine = "DMOZ";
  } elseif (stripos($url,"uk.ask.com") == TRUE) {
      $engine = "Ask UK";
  } elseif (stripos($url,"www.ask.com") == TRUE) {
      $engine = "Ask US";
  } elseif (stripos($url,"search.msn.com") == TRUE || stripos($url,"search.live.com") == TRUE) {
      $engine = "MSN US";
  } elseif (stripos($url,"search.msn.co.uk") == TRUE) {
      $engine = "MSN UK";
  } elseif (stripos($url,"search.msn.co.it") == TRUE) {
      $engine = "MSN Italy";
  } elseif (stripos($url,"netscape.com") == TRUE ) {
      $engine = "Netscape";
  } elseif (stripos($url,"aolsearch.aol.co.uk") == TRUE ) {
      $engine = "AOL UK";
  } elseif (stripos($url,"search.aol.com.au") == TRUE ) {
      $engine = "AOL AU";
  } elseif (stripos($url,"aolsearcht") == TRUE ) {
      $engine = "AOL";
  } elseif (stripos($url,"mail.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Mail";
  } elseif (stripos($url,"images.search.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Images";
  } elseif (stripos($url,"uk.search.yahoo.com") == TRUE ) {
      $engine = "Yahoo! UK";
  } elseif (stripos($url,"finance.groups.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Finance";
  } elseif (stripos($url,"search.yahoo.com") == TRUE || stripos($url,"my.yahoo.com") == TRUE ) {
      $engine = "Yahoo!";
  } elseif (stripos($url,"aolsearch.aol.ca") == TRUE  || stripos($url,"search.aol.ca") == TRUE ) {
      $engine = "AOL CA";
  } elseif (stripos($url,"aolsearch.aol.com") == TRUE  || stripos($url,"search.aol.com") == TRUE ) {
      $engine = "AOL";
  } else {
      # create a new string called $strip_http which contains the url minus http://
      $strip_http = substr($url,7);
      # find the position of the first / so we can locate the search engine or referer domain
      $slash_pos = stripos($strip_http,"/");
      # find search engine or referer domain
      $engine = substr($strip_http,0,$slash_pos);
  } 
     
  return addslashes($engine);
     
}# end function parse_se
     
function parse_terms ($url) {
     
  # decoded URL to remove encoding characters
  $url = urldecode($url);
 
  # if referer url is internal, no query terms needed, but determine campaign tracking and put into referer
 
  if (stripos($url,"ahoo") == TRUE ) {
      if (stripos($url,"&p=") == TRUE) {
        $pos = stripos($url,"&p=");
        $query_url = substr($url,$pos+3);
        $end_pos = stripos($query_url,"&");
        if ($end_pos == null) {
            $terms = str_replace("+"," ",substr($query_url,0));
        } else {
            $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
        }
      } elseif (stripos($url,"?p=") == TRUE) {
        $pos = stripos($url,"?p=");
        $query_url = substr($url,$pos+3);
        $end_pos = stripos($query_url,"&");
        if ($end_pos == null) {
            $terms = str_replace("+"," ",substr($query_url,0));
        } else {
            $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
        }
      } else {
        $terms = "";
      }
  } elseif (stripos($url,"?encquery=") == TRUE) {
        $pos = stripos($url,"?encquery=");
        $query_url = substr($url,$pos+10);
        $end_pos = stripos($query_url,"&");
        if ($end_pos == null) {
            $encoded_query = str_replace("+"," ",substr($query_url,0));
        } else {
            $encoded_query = str_replace("+"," ",substr($query_url,0,$end_pos));
        }
        $FU_AOL = implode( "", file( "http://search.aol.com/aolcom/search?encquery=$encoded_query" ));
        preg_match( '/<title>[^>]*"([^"]+)"<\/title>/', $FU_AOL, $decoded_query );
        $terms = $decoded_query[1];
  } else {
      # finds the beginning position of the query terms
      if (stripos($url,"&q=") == TRUE) {
        $pos = stripos($url,"&q=");
        $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"?q=") == TRUE) {
        $pos = stripos($url,"?q=");
        $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"query=") == TRUE) {
        $pos = stripos($url,"query=");
        $query_url = substr($url,$pos+6);
      } elseif (stripos($url,"?s=") == TRUE) {
        $pos = stripos($url,"?s=");
        $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"&s=") == TRUE) {
        $pos = stripos($url,"&s=");
        $query_url = substr($url,$pos+3);
      }

      $end_pos = stripos($query_url,"&");

      # if pos is null, that means there are no query terms
      if ($pos == null) {
        $terms = "";
        return addslashes($terms);
      }

      if ($end_pos == null) {
        $terms = str_replace("+"," ",substr($query_url,0));
      } else {
        $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
      }
  }
  return addslashes($terms);

}

# ********log referer info in mysql database table "logs"************

# won't log for internal ip addresses, or any ip addresses you put here
if (1==1) {
       
  require "/pwfile";
       
  $username = $usern;
  $password = $passw;
  $database = $datab;
           
  #connect to mysql
  $link = @mysql_connect('localhost',$username,$password);
       
  if (!$link) {
      email_error('Could not login to mysql.'.mysql_error());
  } 
     
  # connect to database in mysql
  $db_connect = @mysql_select_db($database);
     
  if (!$db_connect) {
          email_error("Could not establish connection with database.".mysql_error());
  } 
       
  # data to enter into ins_referer logs table; $name is set up above
  $referer = $_SERVER["HTTP_REFERER"];
  $ref_date = date('m/d/Y H:i:s');
  $browser = "";
  if (isset($_SERVER['HTTP_USER_AGENT'])) {
      $user_agent = get_browser(null,true);
      $browser = $user_agent['browser'];
  } 

  if($referer == "") {
    $referer = "no_referer";
  } 
     
  $referer = addslashes($referer);
  $browser = addslashes($browser);
     
  $searchengine = parse_se($referer);
  $queryterms = parse_terms($referer);
       
  # this will track any campaigns we run, such as links from newsletters, and any others where there is no URL referer, such as browser refresh
  if ((stripos($campaign,"ccn=") !== FALSE)) {
      $referer = substr($campaign,4);
  }
 
  # INSERT statements

  $query = "INSERT INTO forum_table (name, referer, ref_date, searchengine, query, browser) VALUES ('$name','$referer','$ref_date','$searchengine','$queryterms','$browser')";
  $result = @mysql_query($query);

  if (!$result) {
          email_error("Could not insert into $section table.  ".mysql_error());
  }

  @mysql_close();

} #end if internal ip address
# ***********end log  info*****************


King Kovifor 03-19-2008 06:43 PM

Your plugin may be overwriting vBulletin classes. Trying renaming some of your variables by looking into the files referenced by the error message on that specific line. Then modify yours accordingly. This may solve your problem.

Some of the best vBulletin coding practices involves using the $vbulletin->db for all your database interactions. But I believe that


All times are GMT. The time now is 11:17 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01111 seconds
  • Memory Usage 1,765KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete