public function __construct($message, $code, $query, array $params, $previous = null) { $this->query = $query; $this->params = $params; $code = PsUtil::assertClassHasConstVithValue(__CLASS__, 'ERROR_', $code); if ($code == self::ERROR_NOT_CLASSIFIED) { /* * Если ошибка не классифицирована, то мы попробуем её классифицировать */ if (starts_with($message, 'Duplicate entry ')) { $code = self::ERROR_DUPLICATE_ENTRY; } } $message = $message ? $message : 'Unknown db error'; $message = "{$message}. Query: [{$query}]" . ($params ? ', Params: ' . array_to_string($params) . '.' : ''); parent::__construct($message, $code, $previous); }
/** * prepares a statement * * returns the key of the statement * * @param string $statement * @return int */ public function prepare($statement) { if (PVars::get()->debug) { $tm = microtime(); PSurveillance::setPoint('statement_prepare' . $tm); } if (isset($this->result) && $this->result) { $this->result->close(); unset($this->result); } $statement = $this->_dao->MySQLi->prepare($statement); if (!$statement) { $e = new PException('Could not prepare statement!', 1000); $e->addInfo($this->_dao->getErrNo()); $e->addInfo($this->_dao->getErrMsg()); throw $e; } $this->_statement[] = $statement; end($this->_statement); $k = key($this->_statement); $this->_bound = array(); if (PVars::get()->debug) { PSurveillance::setPoint('eostatement_prepare' . $tm); } $this->_i = $k; return $k; }
/** * Sends a confirmation e-mail * * @param string $userId */ public function registerMail($userId) { $User = $this->_model->getUser($userId); if (!$User) { return false; } $handle = $User->handle; $email = $User->email; $key = APP_User::getSetting($userId, 'regkey'); if (!$key) { return false; } $key = $key->value; $confirmUrl = PVars::getObj('env')->baseuri . 'user/confirm/' . $handle . '/' . $key; $registerMailText = array(); require SCRIPT_BASE . 'text/' . PVars::get()->lang . '/apps/user/register.php'; $from = $registerMailText['from_name'] . ' <' . PVars::getObj('config_mailAddresses')->registration . '>'; $subject = $registerMailText['subject']; $Mail = new MOD_mail_Multipart(); $logoCid = $Mail->addAttachment(HTDOCS_BASE . 'images/logo.png', 'image/png'); ob_start(); require 'templates/register_html.php'; $mailHTML = ob_get_contents(); ob_end_clean(); $mailText = ''; require 'templates/register_plain.php'; $Mail->addMessage($mailText); $Mail->addMessage($mailHTML, 'text/html'); $Mail->buildMessage(); $Mailer = Mail::factory(PVars::getObj('config_smtp')->backend, PVars::get()->config_smtp); if (is_a($Mailer, 'PEAR_Error')) { $e = new PException($Mailer->getMessage()); $e->addMessage($Mailer->getDebugInfo()); throw $e; } $rcpts = $email; $header = $Mail->header; $header['From'] = $from; $header['To'] = $email; $header['Subject'] = $subject; $header['Message-Id'] = '<reg' . $userId . '.' . sha1(uniqid(rand())) . '@myTravelbook>'; $r = @$Mailer->send($rcpts, $header, $Mail->message); if (is_object($r) && is_a($r, 'PEAR_Error')) { $e = new PException($r->getMessage()); $e->addInfo($r->getDebugInfo()); throw $e; } }
public function createThumb($dir, $prefix, $max_x = false, $max_y = false, $prefixIsRealName = false, $mode = 'square') { if (!isset($this->hash)) { return FALSE; } if (!$dir) { $dir = dirname($this->file); } if (!$prefix) { $prefix = 't'; } if (!$max_x && !$max_y || intval($max_x) <= 0 && intval($max_y) <= 0) { throw new PException('Neither thumbnail max-width nor max-height provided!'); } $size_x = $this->imageSize[0]; $size_y = $this->imageSize[1]; // old school if (!$max_x || !$max_y) { if ($max_x && intval($max_x) > 0 && $size_x) { $th_size_x = intval($max_x); $th_size_y = intval($size_y * $th_size_x / $size_x); $size_x = $th_size_x; $size_y = $th_size_y; } if ($max_y && intval($max_y) > 0 && $size_y > $max_y) { $th_size_y = intval($max_y); $th_size_x = intval($size_x * $th_size_y / $size_y); } $startx = 0; $starty = 0; $size_x = $this->imageSize[0]; $size_y = $this->imageSize[1]; } else { switch ($mode) { case "ratio": if ($max_x / $size_x >= $max_y / $size_y) { $ratio = $max_y / $size_y; } else { $ratio = $max_x / $size_x; } $startx = 0; $starty = 0; break; default: if ($size_x >= $size_y) { $startx = ($size_x - $size_y) / 2; $starty = 0; $size_x = $size_y; } else { $starty = ($size_y - $size_x) / 2; $startx = 0; $size_y = $size_x; } if ($max_x >= $max_y) { $ratio = $max_y / $size_y; } else { $ratio = $max_x / $size_x; } break; } $th_size_x = $size_x * $ratio; $th_size_y = $size_y * $ratio; } switch (intval($this->imageSize[2])) { // note: fixed this to use the proper constants. IMG_*** are GD constants, IMAGETYPE_*** are PHP constants. // The two DO NOT mix case IMAGETYPE_GIF: $oldImage = ImageCreateFromGIF($this->file); break; case IMAGETYPE_JPEG: $oldImage = ImageCreateFromJPEG($this->file); break; case IMAGETYPE_PNG: $oldImage = ImageCreateFromPNG($this->file); break; case IMAGETYPE_WBMP: $oldImage = ImageCreateFromWBMP($this->file); break; default: $e = new PException('Image type not supported!'); $e->addInfo(print_r($this->imageSize, TRUE)); throw $e; break; } $newImage = ImageCreateTrueColor($th_size_x, $th_size_y); imageCopyResampled($newImage, $oldImage, 0, 0, $startx, $starty, $th_size_x, $th_size_y, $size_x, $size_y); $newFile = tempnam('Lorem ipsum dolor sit amet', 'thumb'); switch ($this->imageSize[2]) { case IMAGETYPE_GIF: ImageTrueColorToPalette($newImage, TRUE, 256); ImageGIF($newImage, $newFile); $mimetype = 'image/gif'; break; case IMAGETYPE_JPEG: ImageJPEG($newImage, $newFile); $mimetype = 'image/jpeg'; break; case IMAGETYPE_PNG: ImagePNG($newImage, $newFile); $mimetype = 'image/png'; break; case IMAGETYPE_WBMP: ImageWBMP($newImage, $newFile); $mimetype = 'image/wbmp'; break; } $dest = $dir . '/' . $prefix; if (!$prefixIsRealName) { $dest .= $this->hash; } if (!@copy($newFile, $dest)) { return false; } unlink($newFile); return true; }
/** * performs a query * * @param string $statement * @return PDBStatement_mysql */ public function query($statement) { try { $s = new PDBStatement_mysqli($this); if (!$s->query($statement)) { $e = new PException('MySQL Error!', 1000); $e->addInfo($this->getErrNo()); $e->addInfo($this->getErrMsg()); throw $e; } return $s; } catch (PException $e) { throw $e; } }
public function query($query) { if (PVars::get()->debug) { $start_time = microtime(true); } $q = @mysql_query($query, $this->_dao->cr); if (!$q) { $e = new PException('MySQL error!', 1000); $e->addInfo('Statement: ' . $query); $e->addInfo($this->_dao->getErrNo()); $e->addInfo($this->_dao->getErrMsg()); throw $e; } $this->result = $q; $this->pos = 0; $q = PVars::get()->queries + 1; PVars::register('queries', $q); if (PVars::get()->debug) { $q = PVars::get()->query_history; $query_time = sprintf("%.1f", (microtime(true) - $start_time) * 1000); $q[] = "({$query_time} ms) {$query}"; PVars::register('query_history', $q); } return true; }