/** * Конструктор * * @param mixed $value Число (0xFFEEDD), массив (array(0xFF, 0xEE, 0xDD)), либо строка ('#FFEEDD' или название web-цвета) */ function __construct($value) { /** * Если число сохраняем */ if (is_int($value)) { $this->RGB = $value; } else { if (is_array($value) && count($value) == 3) { $temp = array_values($value); $this->RGB = ($temp[0] & 0xff) << 16 | ($temp[1] & 0xff) << 8 | $temp[2] & 0xff; } else { if (is_string($value)) { if ($value[0] == '#') { $this->RGB = intval(base_convert(trim($value, '# '), 16, 10)) & 0xffffff; } else { if (isset(self::$webColors[$temp = strtolower($value)])) { $this->RGB = self::$webColors[$temp]; } } } } } /** * Иначе выдаём ошибку */ if ($this->RGB === FALSE) { triggerError(sprintf(Open_Text::getInstance()->dget('errors', 'The value "<b>%s</b>" cannot be converted to color'), $value), E_USER_WARNING); } }
function __set($name, $value) { if (strcmp($name, 'images') === 0 || strcmp($name, 'otherSpecs') === 0) { \triggerError('Cannot access private property ' . __NAMESPACE__ . '\\' . __CLASS__ . '::' . $name . ' (from magic setter)'); } else { $this->{$name} = $value; } }
/** * Конструктор * * @param mixed $value Ресурс открытой картинки, строка-путь к картинке или с данными, число ширина картинки * @param int $height Если первое значение число, то оно является шириной новой картинки, а это высота. Если высота не передана, то будет создана квадратная картинка */ function __construct($value, $height = NULL) { /** * Если ресурс сохраняем */ if (is_resource($value)) { $this->resource = $value; } else { if (is_string($value)) { if (file_exists($value)) { switch (pathinfo($value, PATHINFO_EXTENSION)) { case 'png': $this->resource = imagecreatefrompng($value); break; case 'jpg': case 'jpeg': $this->resource = imagecreatefromjpeg($value); break; case 'gif': $this->resource = imagecreatefromgif($value); break; } } else { $this->resource = imagecreatefromstring($value); } } else { if (is_int($value)) { $width = $value; $height = isset($height) ? (int) $height : $width; $this->resource = imagecreatetruecolor($width, $height); } } } /** * Выдаём ошибку */ if ($this->resource === FALSE) { triggerError(sprintf(Open_Text::getInstance()->dget('errors', 'The value "<b>%s</b>" cannot be converted to image'), $value), E_USER_WARNING); } /** * Преобразование к truecolor */ $this->convertToTruecolor(); }
function AMO_SQL() { global $shadow_config; require_once "DB.php"; /** * If our current script is in the shadow array, we should * connect to the shadow db instead of the default. */ if (defined('SCRIPT_NAME') && in_array(SCRIPT_NAME, $shadow_config)) { $shadow_dsn = array('phptype' => 'mysql', 'dbsyntax' => 'mysql', 'username' => SHADOW_USER, 'password' => SHADOW_PASS, 'hostspec' => SHADOW_HOST, 'database' => SHADOW_NAME, 'port' => SHADOW_PORT); $this->connect($shadow_dsn); } else { $dsn = array('phptype' => 'mysql', 'dbsyntax' => 'mysql', 'username' => DB_USER, 'password' => DB_PASS, 'hostspec' => DB_HOST, 'database' => DB_NAME, 'port' => DB_PORT); $this->connect($dsn); } // Test connection; display "gone fishing" on failure. if (DB::isError($this->db)) { triggerError($this->error, 'site-down.tpl'); } }
public function triggerError($errstr, $errno) { triggerError($errstr, $errno); }
if (!$_auth->validSession()) { //id is already verified to be numeric from above header('Location: ' . WEB_PATH . "/login.php?dest=comment&aid={$_GET['aid']}"); exit; } // If there are errors, this will be populated $_errors = array(); // This will be used in queries and the template $addon = new AddOn($_GET['aid']); // If the comment is added successfully, this will toggle (used in the template) $added_comment = false; // They're posting a comment if (isset($_POST['c_submit'])) { if (!(array_key_exists('c_rating', $_POST) && array_key_exists('c_title', $_POST) && array_key_exists('c_comments', $_POST))) { //This should never happen, but hey... triggerError('There was an error processing your request.'); } // Check all our input to make sure something is there, and it is appropriate. // If it isn't, make $_bad_input=true which means we'll print the form back out // with an error message. (By using booleans here, we keep the error messages in // the .tpl) $_bad_input = false; if (!is_numeric($_POST['c_rating']) || $_POST['c_rating'] < 0 || $_POST['c_rating'] > 5) { $_errors['c_rating'] = true; $_bad_input = true; } if (empty($_POST['c_title'])) { $_errors['c_title'] = true; $_bad_input = true; } if (empty($_POST['c_comments'])) {
<?php require_once LIB . '/error.php'; $error = 'Test Error<br>'; $error .= 'Generated: ' . date("r"); $error .= '<pre>' . print_r($_SERVER, true) . '</pre>'; triggerError($error, 'site-down.tpl');
restore_error_handler(); if (!$rs) { // never called } } $end = microtime(true); echo $end - $start . PHP_EOL; echo 'error suppression (use last error): '; $start = microtime(true); for ($i = 0; $i < $max; $i++) { $rs = @triggerError(); if (!$rs) { $err = error_get_last(); $globalLastErrorMsg = $err['message']; // do somethink with $globalLastErrorMsg } } $end = microtime(true); echo $end - $start . PHP_EOL; echo 'error handler (use last error): '; $start = microtime(true); for ($i = 0; $i < $max; $i++) { set_error_handler('tmpErrorHandler'); $rs = triggerError(); restore_error_handler(); if (!$rs) { // do somethink with $globalLastErrorMsg } } $end = microtime(true); echo $end - $start . PHP_EOL;
/** * Показать 404-ю * * @param string $message Текст ошибки */ function trigger404($message = FALSE) { if ($message === FALSE) { $message = Open_Text::getInstance()->dget('errors', Open_Config::getInstance()->get('default_404_message')); } triggerError($message, E_404); }
/** * Отправить запрос, получить результат * Строка запроса НЕ должна заканчиваться точкой с запятой (претензия из мануала) * Не забываем пользоваться методом escape(), перед внесением данных в запрос, чтобы сделать данные безопасными * Просто выполняет запрос и возвращает результат * * @param string $query * @return mixed */ public function query($query) { $link = $this->getLink(); if (self::LOGGING) { $start = microtime(true); } $result = mysql_query($query, $link) or triggerError('<pre><b>#' . mysql_errno($link) . '</b> - ' . mysql_error($link) . '<br/><br/><b>Query</b>:<br/>' . htmlentities($query, ENT_COMPAT, CHARSET) . '</pre>', E_DB); if (self::LOGGING) { $end = microtime(true); $log = 'MySQL query: ' . $query . ' | executed in ' . numberFormat($end - $start, 6) . 's'; error_log($log, 0); } return $result; }
$addon = new Addon($sql['aid']); } // Get our comment ID. if (isset($_GET['cid'])) { $clean['cid'] = intval($_GET['cid']); $sql['cid'] =& $clean['cid']; $db->query("SELECT * FROM feedback WHERE CommentID = '{$sql['cid']}'", SQL_INIT, SQL_ASSOC); $comment = $db->record; $tpl->assign('comment', $comment); } // Get whether helpful or not... if (isset($_GET['r'])) { switch ($_GET['r']) { case 'yes': $clean['r'] = 'yes'; $clean['helpful'] = 'helpful'; break; case 'no': $clean['r'] = 'no'; $clean['helpful'] = 'not helpful'; break; } } // If our form was submitted, try to process the results. $success = $db->query("\n UPDATE\n feedback\n SET\n `helpful-{$clean['r']}` = `helpful-{$clean['r']}` + 1\n WHERE\n CommentID = {$sql['cid']}\n", SQL_NONE); if ($success) { $tpl->assign('success', true); } else { triggerError('Query failed. Could not enter comment rating.'); } $tpl->assign(array('title' => 'Rate a Comment for ' . $addon->Name, 'content' => 'ratecomment.tpl', 'addon' => $addon, 'clean' => $clean, 'sidebar' => 'inc/addon-sidebar.tpl'));