/**
  * If an error has occured, we print a message. If 'halt_on_sql_error' is
  * set, we die(), else we continue.
  *
  * @param string $error_msg
  *
  */
 function error($error_msg = "")
 {
     global $cfg;
     $error_date = date("F j, Y, g:i a");
     $error_page = "<div style='border: 1px solid #AAA; padding: 4px; background-color: #EEE; font-family: Consolas, Courier, \"Courier New\", monospace; font-size: 80%;'><strong>SQLFactory Error</strong>" . "\n\nThere appears to be an error while trying to complete your request.\n\n" . "<strong>Query: </strong>      " . htmlentities($sql_query) . "\n" . "<strong>SQL error:</strong> " . htmlentities($error_msg) . "\n" . "<strong>Error code:</strong>  {$error_no}\n" . "<strong>Date:</strong>        {$error_date}\n</div>\n";
     echo nl2br($error_page);
     if (function_exists('debug_printbacktrace')) {
         // call debug_printbacktrace if it's available..
         debug_printbacktrace();
     }
     if ($this->halt_on_sql_error == true) {
         die;
     }
 }
Beispiel #2
0
 /**
  * Performs a query. Either pass the query to e executed as a parameter,
  *
  * @param string query
  */
 function query($query = "")
 {
     global $PIVOTX, $timetaken;
     // If there's no DB connection yet, set one up if we can.
     if (!$this->connection()) {
         return false;
     }
     // perhaps use the cached query
     if ($query == "") {
         $query = $this->cached_query;
     }
     // Set the last_query
     $this->last_query = $query;
     $now = timeTaken('int');
     // execute it.
     $this->sql_result = @$this->sql_doquery($query, $this->sql_link);
     // If we're profiling, we use the following to get an array of all queries.
     // We also debug queries that took relatively long to perform.
     if ($PIVOTX['config']->get('debug')) {
         $querytimetaken = round(timeTaken('int') - $now, 4);
         if (timeTaken('int') - $now > 0.4) {
             debug("\nStart: " . $now . " - timetaken: " . $querytimetaken);
             debug(htmlentities($query) . "\n\n");
             debug_printbacktrace();
         }
         $query = preg_replace("/\\s+/", " ", $query);
         // If debug is enabled, we add a small comment to the query, so that it's
         // easier to track where it came from
         if (function_exists('debug_backtrace')) {
             $trace = debug_backtrace();
             $comment = sprintf(" -- %s - %s():%s ", basename($trace[0]['file']), $trace[1]['function'], $trace[0]['line']);
             $query .= $comment;
         }
         //echo "<pre>\n"; print_r($query); echo "</pre>";
         $GLOBALS['query_log'][] = $query . " -- {$querytimetaken} sec. ";
     }
     if ($this->sql_result === false) {
         // If an error occured, we output the error.
         $this->error('', $this->last_query, $this->sql_errno($this->sql_link));
         $this->num_affected_rows = 0;
         return false;
     } else {
         // Count the num of results, and raise the total query count.
         $timetaken['query_count']++;
         $timetaken['sql'] += timetaken('int') - $now;
         $this->num_affected_rows = $this->affected_rows();
         return true;
     }
 }
Beispiel #3
0
function saveSerialize($filename, &$data)
{
    $filename = fixPath($filename);
    $ser_string = "<?php /* bolt */ die(); ?>" . serialize($data);
    // disallow user to interrupt
    ignore_user_abort(true);
    $old_umask = umask(0111);
    // open the file and lock it.
    if ($fp = fopen($filename, "a")) {
        if (flock($fp, LOCK_EX | LOCK_NB)) {
            // Truncate the file (since we opened it for 'appending')
            ftruncate($fp, 0);
            // Write to our locked, empty file.
            if (fwrite($fp, $ser_string)) {
                flock($fp, LOCK_UN);
                fclose($fp);
            } else {
                flock($fp, LOCK_UN);
                fclose($fp);
                // todo: handle errors better.
                echo "Error opening file<br/><br/>The file <b>{$filename}</b> could not be written! <br /><br />Try logging in with your ftp-client and check to see if it is chmodded to be readable by the webuser (ie: 777 or 766, depending on the setup of your server). <br /><br />Current path: " . getcwd() . ".";
                die;
            }
        } else {
            fclose($fp);
            // todo: handle errors better.
            echo "Error opening file<br/><br/>Could not lock <b>{$filename}</b> for writing! <br /><br />Try logging in with your ftp-client and check to see if it is chmodded to be readable by the webuser (ie: 777 or 766, depending on the setup of your server). <br /><br />Current path: " . getcwd() . ".";
            die;
        }
    } else {
        // todo: handle errors better.
        echo "Error opening file<br/><br/>The file <b>{$filename}</b> could not be opened for writing! <br /><br />Try logging in with your ftp-client and check to see if it is chmodded to be readable by the webuser (ie: 777 or 766, depending on the setup of your server). <br /><br />Current path: " . getcwd() . ".";
        debug_printbacktrace();
        die;
    }
    umask($old_umask);
    // reset the users ability to interrupt the script
    ignore_user_abort(false);
    return true;
}
Beispiel #4
0
/**
 * piv_error prints an error message, does a debug backtrace print out
 * and exits.
 *
 * On the admin pages it will just display the text on the current page and
 * add the page footer (if endpage is equal to 1). On weblog pages it will use
 * the extra page template for the current weblog.
 *
 * @param string $name
 * @param string $message
 * @param boolean $endpage
 */
function piv_error($name, $message, $endpage = 0)
{
    global $db, $Current_weblog, $Weblogs, $Pivot_Vars;
    if (!isset($db)) {
        $db = new db();
    }
    if (!isset($Current_weblog)) {
        reset($Weblogs);
        if (isset($Pivot_Vars['w'])) {
            $Current_weblog = weblog_from_para($Pivot_Vars['w']);
            if (!$Current_weblog) {
                $Current_weblog = key($Weblogs);
            }
        } else {
            $Current_weblog = key($Weblogs);
        }
    }
    debug_printbacktrace();
    $text = "<div class='pivot-error'>\n<h2>{$name}</h2>\n\n" . "<p>{$message}</p>\n</div>\n";
    if ($endpage == 1 || !defined('LIVEPAGE') && !defined('INWEBLOG')) {
        echo $text;
        PageFooter();
        exit;
    }
    // Use the extra template for the current weblog
    if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") {
        $template_html = load_template($Weblogs[$Current_weblog]['extra_template']);
    } else {
        $template_html = load_template($Weblogs[$Current_weblog]['archive_template']);
    }
    // Match and replace the [[weblog]] tags for the error output
    $template_html = replace_subweblogs_templates($template_html, $text);
    if (!$template_html) {
        ErrorOut("Could not load template file: <i>{$template}</i> [does not exist]");
    } else {
        $output = $template_html;
        $output = parse_step4($output);
    }
    echo $output;
    flush();
    exit;
}