function save($file) { if (!$file['hash']) { $file['hash'] = MD5(MD5($file['data']) . time()); } if (!$file['size']) { $file['size'] = strlen($file['data']); } //TODO: Do chunked INSERTs - if (($mps = db_get_variable('max_allowed_packet')) && $file['size'] > $mps * 0.7) { @db_set_variable('max_allowed_packet', $file['size'] + $mps); } $sql = 'INSERT INTO ' . FILE_TABLE . ' SET created=NOW() ' . ',type=' . db_input($file['type']) . ',size=' . db_input($file['size']) . ',name=' . db_input($file['name']) . ',hash=' . db_input($file['hash']) . ',filedata=' . db_input($file['data']); return db_query($sql) ? db_insert_id() : 0; }
function db_timezone() { return db_get_variable('time_zone'); }
function __construct($body, $type = 'text', $options = array()) { $type = strtolower($type); if (!in_array($type, static::$types)) { throw new Exception("{$type}: Unsupported ThreadBody type"); } $this->body = (string) $body; if (strlen($this->body) > 250000) { $max_packet = db_get_variable('max_allowed_packet', 'global'); // Truncate just short of the max_allowed_packet $this->body = substr($this->body, 0, $max_packet - 2048) . ' ... ' . _S('(truncated)'); } $this->type = $type; $this->options = array_merge($this->options, $options); }