Пример #1
0
 /**
  * Send emails
  *
  * @param string $to - defaults to SITE_EMAIL
  * @param string $subject - defaults to "No Subject";
  * @param string $body - returns false if empty
  * @param string $headers default is "From: " . SITE_EMAIL . "\r\nReply-To: " . SITE_EMAIL . "\r\nX-Priority: 3\r\n";
  * @param string $type - default is "email", but you can write to a "log" file, print to "screen" or "return" an array of the content
  * @return array|false - only if $type = "return"
  */
 public function email($to = '', $subject = '', $body = '', $headers = '', $type = 'email', $isHtml = true)
 {
     if (!is_object($this->email)) {
         $this->email = EmailFunctions::instance();
     }
     $this->email->to = $to;
     $this->email->subject = $subject;
     $this->email->body = $body;
     $this->email->headers = $headers;
     $this->email->type = $type;
     $this->email->isHtml = $isHtml;
     return $this->email->doEmail($this);
 }
Пример #2
0
 function query($query)
 {
     // This keeps the connection alive for very long running scripts
     if ($this->num_queries >= 500) {
         $this->num_queries = 0;
         $this->disconnect();
         $this->quick_connect($this->dbuser, $this->dbpassword, $this->dbname, $this->dbhost, $this->encoding);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Start timer
     $this->timer_start($this->num_queries);
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         // Keep tack of how long all queries have taken
         $this->timer_update_global($this->num_queries);
         // Trace all queries
         if ($this->use_trace_log) {
             $this->trace_log[] = $this->debug(false);
         }
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->selectDB($this->dbname, $this->encoding);
         // No existing connection at this point means the server is unreachable
         if (!isset($this->dbh) || !$this->dbh) {
             return false;
         }
     }
     // Perform the query via std mysql_query function..
     $this->result = @mysql_query($query, $this->dbh);
     // If there is an error then take note of it..
     if ($str = @mysql_error($this->dbh)) {
         if (defined('DEBUG') && DEBUG == 'true') {
             $subject = SITE_NAME . " Database Error";
             $body = SITE_NAME . " Database Error\r\n\r\n";
             $body .= "Date: " . date('d M Y H:i:s') . " (timezone: " . date_default_timezone_get() . ")\r\n\r\n";
             $body .= "SQL query:\r\n";
             $body .= $query . "\r\n\r\n";
             $body .= "PHP error log:\r\n";
             $body .= $str . "\r\n\r\n";
             if (isset($this->h)) {
                 $body .= "Current User: "******" (id: " . $this->h->currentUser->id . ")\r\n";
                 $body .= "User Role: " . $this->h->currentUser->role . "\r\n";
                 $body .= "Page Name: " . $this->h->pageName . "\r\n";
                 $body .= "Sub Page: " . $this->h->subPage . "\r\n";
                 $body .= "Plugin: " . $this->h->plugin->folder . "\r\n\r\n";
             }
             $body .= "If you need help, visit the forums at http://forums.hotarucms.org\r\n";
             // we can avoid using the $h object (which we might not have) by calling EmailFunctions directly.
             require_once LIBS . 'EmailFunctions.php';
             $emailFunctions = new EmailFunctions();
             $emailFunctions->subject = $subject;
             $emailFunctions->body = $body;
             $emailFunctions->doEmail();
         }
         $is_insert = true;
         $this->register_error($str);
         $this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     if (preg_match("/^(insert|delete|update|replace|truncate|drop|create|alter|set)\\s+/i", $query)) {
         $is_insert = true;
         $this->rows_affected = @mysql_affected_rows($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $this->insert_id = @mysql_insert_id($this->dbh);
         }
         // Return number fo rows affected
         $return_val = $this->rows_affected;
     } else {
         $is_insert = false;
         // Take note of column info
         $i = 0;
         while ($i < @mysql_num_fields($this->result)) {
             $this->col_info[$i] = @mysql_fetch_field($this->result);
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @mysql_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @mysql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     // Keep tack of how long all queries have taken
     $this->timer_update_global($this->num_queries);
     // Trace all queries
     if ($this->use_trace_log) {
         $this->trace_log[] = $this->debug(false);
     }
     return $return_val;
 }
Пример #3
0
 function query($query = '')
 {
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function.. (Borrowed from Wordpress)
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         $this->timer_start();
     }
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         // Nick edit: Although it cached queries with zero results, the get_cache
         // function returns false (i.e 0) if there are zero rows, so if 0, I've made
         // it store and return "empty" instead, forcing the above queryto return true
         // and the cache (with no results) to be used. This saves making repeated SQL
         // queries that we already know return an empty set of results.
         // I did this because the pluginHook function ramps up the query counts
         // but rarely returns anything!
         return $cache;
     } else {
         //echo $query . "<br />"; // for testing purposes
     }
     // Count how many queries there have been
     $this->num_queries++;
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->selectDB($this->dbname);
     }
     // Perform the query via std mysql_query function..
     $this->result = @mysql_query($query, $this->dbh);
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         // Borrowed from Wordpress
         $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
     }
     // If there is an error then take note of it..
     if ($str = @mysql_error($this->dbh)) {
         if (defined('DEBUG') && DEBUG == 'true') {
             $subject = SITE_NAME . " Database Error";
             $body = SITE_NAME . " Database Error\r\n\r\n";
             $body .= "Date: " . date('d M Y H:i:s') . " (timezone: " . date_default_timezone_get() . ")\r\n\r\n";
             $body .= "SQL query:\r\n";
             $body .= $query . "\r\n\r\n";
             $body .= "PHP error log:\r\n";
             $body .= $str . "\r\n\r\n";
             if (isset($this->h)) {
                 $body .= "Current User: "******" (id: " . $this->h->currentUser->id . ")\r\n";
                 $body .= "User Role: " . $this->h->currentUser->role . "\r\n";
                 $body .= "Page Name: " . $this->h->pageName . "\r\n";
                 $body .= "Sub Page: " . $this->h->subPage . "\r\n";
                 $body .= "Plugin: " . $this->h->plugin->folder . "\r\n\r\n";
             }
             $body .= "If you need help, visit the forums at http://hotarucms.org\r\n";
             // we can avoid using the $h object (which we might not have) by calling EmailFunctions directly.
             require_once LIBS . 'EmailFunctions.php';
             $emailFunctions = new EmailFunctions();
             $emailFunctions->subject = $subject;
             $emailFunctions->body = $body;
             $emailFunctions->doEmail();
         }
         $is_insert = true;
         $this->register_error($str);
         $this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @mysql_affected_rows();
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $this->insert_id = @mysql_insert_id($this->dbh);
         }
         // Return number fo rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         if (is_resource($this->result)) {
             while ($i < @mysql_num_fields($this->result)) {
                 $this->col_info[$i] = @mysql_fetch_field($this->result);
                 $i++;
             }
         }
         // Store Query Results
         $num_rows = 0;
         if (is_resource($this->result)) {
             while ($row = @mysql_fetch_object($this->result)) {
                 // Store relults as an objects within main array
                 $this->last_result[$num_rows] = $row;
                 $num_rows++;
             }
         }
         if (is_resource($this->result)) {
             @mysql_free_result($this->result);
         }
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }