本文整理汇总了PHP中Jaws_Error::raiseError方法的典型用法代码示例。如果您正苦于以下问题:PHP Jaws_Error::raiseError方法的具体用法?PHP Jaws_Error::raiseError怎么用?PHP Jaws_Error::raiseError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jaws_Error
的用法示例。
在下文中一共展示了Jaws_Error::raiseError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Auth
/**
* Authenticate user/password
*
* @access public
* @param string $user User's name or email
* @param string $password User's password
* @return mixed Array of user's information otherwise Jaws_Error
*/
function Auth($user, $password)
{
if (!function_exists('imap_open')) {
return Jaws_Error::raiseError('Undefined function imap_open()', __FUNCTION__);
}
$mbox = @imap_open('{' . $this->_Server . ':' . $this->_Port . ($this->_SSL ? '/imap/ssl' : '') . '}INBOX', $user, $password);
if ($mbox) {
@imap_close($mbox);
$result = array();
$result['id'] = strtolower('imap:' . $user);
$result['internal'] = false;
$result['username'] = $user;
$result['superadmin'] = false;
$result['internal'] = false;
$result['groups'] = array();
$result['nickname'] = $user;
$result['concurrents'] = 0;
$result['email'] = '';
$result['url'] = '';
$result['avatar'] = 'gadgets/Users/Resources/images/photo48px.png';
$result['language'] = '';
$result['theme'] = '';
$result['editor'] = '';
$result['timezone'] = null;
return $result;
}
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'), __FUNCTION__);
}
示例2: GetCurrentRootDir
/**
* Get files of the current root dir
*
* @access public
* @param string $path Current directory
* @return array A list of directories or files of a certain directory
*/
function GetCurrentRootDir($path)
{
$path = trim($path, '/');
$path = str_replace('..', '', $path);
$fModel = $this->gadget->model->load('Files');
if (!is_dir($fModel->GetFileBrowserRootDir() . $path)) {
return Jaws_Error::raiseError(_t('FILEBROWSER_ERROR_DIRECTORY_DOES_NOT_EXISTS'), 404, JAWS_ERROR_NOTICE);
}
$tree = array();
$tree['/'] = '/';
if (!empty($path)) {
$parent_path = substr(strrev($path), 1);
if (strpos($parent_path, '/')) {
$parent_path = strrev(substr($parent_path, strpos($parent_path, '/'), strlen($parent_path)));
} else {
$parent_path = '';
}
$vpath = '';
foreach (explode('/', $path) as $k) {
if ($k != '') {
$vpath .= '/' . $k;
$tree[$vpath] = $k;
}
}
} else {
$tree[] = $path;
}
return $tree;
}
示例3: SaveSettings
/**
* Updates the Tag gadget settings
*
* @access public
* @param string $tagResultLimit Allow comments?
* @return mixed True on success or Jaws_Error on failure
*/
function SaveSettings($tagResultLimit)
{
$res = $this->gadget->registry->update('tag_results_limit', $tagResultLimit);
if ($res === false) {
return Jaws_Error::raiseError(_t('TAGS_ERROR_CANT_UPDATE_PROPERTIES'), __FUNCTION__);
}
return true;
}
示例4: SaveSettings
/**
* Updates the Comments gadget settings
*
* @access public
* @param string $allowComments Allow comments?
* @param int $defaultStatus Default comment status
* @param int $orderType Order type
* @return mixed True on success or Jaws_Error on failure
*/
function SaveSettings($allowComments, $defaultStatus, $orderType)
{
$res = $this->gadget->registry->update('allow_comments', $allowComments);
$res = $res && $this->gadget->registry->update('default_comment_status', $defaultStatus);
$res = $res && $this->gadget->registry->update('order_type', $orderType);
if ($res === false) {
return Jaws_Error::raiseError(_t('COMMENTS_ERROR_CANT_UPDATE_PROPERTIES'), __FUNCTION__);
}
return true;
}
示例5: GetForum
/**
* Returns array of forum properties
*
* @access public
* @param int $fid forum ID
* @return mixed Array of forum properties or Jaws_Error on error
*/
function GetForum($fid)
{
$perm = $this->gadget->GetPermission('ForumPublic', $fid);
if (is_null($perm)) {
return Jaws_Error::raiseError(_t('GLOBAL_HTTP_ERROR_CONTENT_404'), 404, JAWS_ERROR_NOTICE);
}
if (!$perm) {
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_ACCESS_DENIED'), 403, JAWS_ERROR_NOTICE);
}
$table = Jaws_ORM::getInstance()->table('forums');
$table->select('id:integer', 'gid:integer', 'title', 'description', 'fast_url', 'topics:integer', 'posts:integer', 'order:integer', 'locked:boolean', 'published:boolean');
if (is_numeric($fid)) {
$table->where('id', $fid);
} else {
$table->where('fast_url', $fid);
}
return $table->fetchRow();
}
示例6: open
/**
* Listen network port over given address
*
* @access public
* @param string $path path of web socket server
* @param string $origin indicates the origin of the script establishing the connection
* @param mixed $callback callback function loaded when data received
* @return mixed True on success or Jaws_Error on failure
*/
public function open($path, $origin = '', $callback = null)
{
if (!($this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
return $this->close();
}
// set send/receive timeouts
socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $this->receive_timeout, 'usec' => 0));
socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $this->send_timeout, 'usec' => 0));
// trying connect to WebSocket server
if (false === @socket_connect($this->socket, $this->address, $this->port)) {
return $this->close($this->socket);
}
$randomKey = base64_encode(Jaws_Utils::RandomText(16, true, true, true));
$header = "GET {$path} HTTP/1.1\r\n";
$header .= "Host: {$this->address}:{$this->port}\r\n";
$header .= "Upgrade: websocket\r\n";
$header .= "Connection: Upgrade\r\n";
$header .= "Sec-WebSocket-Key: {$randomKey}\r\n";
if (!empty($origin)) {
$header .= "Sec-WebSocket-Origin: {$origin}\r\n";
}
$header .= "Sec-WebSocket-Version: 13\r\n";
$header .= "\r\n";
// send hand-shake header
if (false === @socket_write($this->socket, $header)) {
return $this->close($this->socket);
}
// trying receive hand-shake response
if (false === @socket_recv($this->socket, $response, 1024, 0)) {
$last_error = error_get_last();
return $this->close($this->socket, $last_error['message']);
}
$expectedKey = $randomKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
$expectedKey = base64_encode(sha1($expectedKey, true));
if (preg_match('#Sec-WebSocket-Accept: (.*)\\r\\n\\r\\n$#imU', $response, $matches)) {
$acceptKey = trim($matches[1]);
if ($acceptKey === $expectedKey) {
return true;
}
}
$this->close($this->socket);
return Jaws_Error::raiseError('Response header not valid');
}
示例7: preg_replace
/**
* Loads the gadget hook file class in question, makes a instance and
* stores it globally for later use so we do not have duplicates
* of the same instance around in our code.
*
* @access public
* @param string $hook Hook name
* @return mixed Hook class object on successful, Jaws_Error otherwise
*/
public function &load($hook)
{
// filter non validate character
$hook = preg_replace('/[^[:alnum:]_]/', '', $hook);
if (!isset($this->objects[$hook])) {
$classname = $this->gadget->name . '_Hooks_' . $hook;
$file = JAWS_PATH . 'gadgets/' . $this->gadget->name . "/Hooks/{$hook}.php";
if (!file_exists($file)) {
return Jaws_Error::raiseError("File [{$file}] not exists!", __FUNCTION__);
}
include_once $file;
if (!Jaws::classExists($classname)) {
return Jaws_Error::raiseError("Class [{$classname}] not exists!", __FUNCTION__);
}
$this->objects[$hook] = new $classname($this->gadget);
$GLOBALS['log']->Log(JAWS_LOG_DEBUG, "Loaded gadget hook: [{$classname}]");
}
return $this->objects[$hook];
}
示例8: userAuthentication
/**
* User authentication
*
* @access public
* @param string $user username
* @param string $password password
* @return mixed True or Jaws_Error
*/
function userAuthentication($username, $password)
{
$authType = $GLOBALS['app']->Registry->fetch('authtype', 'Users');
$authType = preg_replace('/[^[:alnum:]_\\-]/', '', $authType);
$authFile = JAWS_PATH . 'include/Jaws/Auth/' . $authType . '.php';
if (empty($authType) || !file_exists($authFile)) {
$GLOBALS['log']->Log(JAWS_LOG_NOTICE, $authFile . ' file doesn\'t exists, using default authentication type');
$authType = 'Default';
}
if ($username === '' && $password === '') {
$result = Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'), __FUNCTION__, JAWS_ERROR_NOTICE);
}
require_once JAWS_PATH . 'include/Jaws/Auth/' . $authType . '.php';
$className = 'Jaws_Auth_' . $authType;
$objAuth = new $className();
$result = $objAuth->Auth($username, $password);
if (!Jaws_Error::IsError($result)) {
$GLOBALS['app']->Session->SetAttribute('logged', true);
$GLOBALS['app']->Session->SetAttribute('user', $result['id']);
$GLOBALS['app']->Session->SetAttribute('groups', $result['groups']);
$GLOBALS['app']->Session->SetAttribute('superadmin', $result['superadmin']);
}
return $result;
}
示例9: GetTopics
/**
* Get topics of forum
*
* @access public
* @param int $fid Forum ID
* @param int $published Is Published ?
* @param int $uid User id
* @param int $limit Count of topics to be returned
* @param int $offset Offset of data array
* @return mixed Array of topics or Jaws_Error on failure
*/
function GetTopics($fid, $published = null, $uid = null, $limit = 0, $offset = null)
{
$perm = $this->gadget->GetPermission('ForumPublic', $fid);
if (is_null($perm)) {
return Jaws_Error::raiseError(_t('GLOBAL_HTTP_ERROR_CONTENT_404'), 404, JAWS_ERROR_NOTICE);
}
if (!$perm) {
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_ACCESS_DENIED'), 403, JAWS_ERROR_NOTICE);
}
$table = Jaws_ORM::getInstance()->table('forums_topics');
$table->select('forums_topics.id:integer', 'fid:integer', 'subject', 'views:integer', 'replies:integer', 'first_post_id:integer', 'first_post_uid:integer', 'first_post_time:integer', 'last_post_id:integer', 'last_post_uid:integer', 'last_post_time:integer', 'fuser.username as first_username', 'fuser.nickname as first_nickname', 'luser.username as last_username', 'luser.nickname as last_nickname', 'locked:boolean', 'published:boolean');
$table->join('users as fuser', 'forums_topics.first_post_uid', 'fuser.id', 'left');
$table->join('users as luser', 'forums_topics.last_post_uid', 'luser.id', 'left');
$table->where('fid', $fid)->orderBy('last_post_time desc')->limit($limit, $offset);
if (empty($uid)) {
if (!is_null($published)) {
$table->and()->where('published', (bool) $published);
}
} else {
$published = is_null($published) ? true : (bool) $published;
$table->and()->openWhere('first_post_uid', (int) $uid)->or()->closeWhere('published', $published);
}
return $table->fetchAll();
}
示例10: Run
/**
* Does any actions required to finish the stage, such as DB queries.
*
* @access public
* @return bool|Jaws_Error Either true on success, or a Jaws_Error
* containing the reason for failure.
*/
function Run()
{
if (version_compare($_SESSION['upgrade']['InstalledVersion'], '0.9.0', '<')) {
return Jaws_Error::raiseError(_t('UPGRADE_REPORT_NOT_SUPPORTED'), 0, JAWS_ERROR_WARNING);
}
if (is_dir(JAWS_DATA . "languages")) {
// transform customized translated files
$rootfiles = array('Global.php', 'Date.php', 'Install.php', 'Upgrade.php');
$languages = scandir(JAWS_DATA . 'languages');
foreach ($languages as $lang) {
if ($lang == '.' || $lang == '..') {
continue;
}
$ostr = "define('_" . strtoupper($lang) . '_';
$nstr = "define('_" . strtoupper($lang) . '_DATA_';
// gadgets
if (is_dir(JAWS_DATA . "languages/{$lang}/gadgets")) {
$lGadgets = scandir(JAWS_DATA . "languages/{$lang}/gadgets");
foreach ($lGadgets as $lGadget) {
if ($lGadget == '.' || $lGadget == '..') {
continue;
}
$fstring = @file_get_contents(JAWS_DATA . "languages/{$lang}/gadgets/{$lGadget}");
$fstring = strtr($fstring, array($nstr => $nstr, $ostr => $nstr));
@file_put_contents(JAWS_DATA . "languages/{$lang}/gadgets/{$lGadget}", $fstring);
}
}
// plugins
if (is_dir(JAWS_DATA . "languages/{$lang}/plugins")) {
$lPlugins = scandir(JAWS_DATA . "languages/{$lang}/plugins");
foreach ($lPlugins as $lPlugin) {
if ($lPlugin == '.' || $lPlugin == '..') {
continue;
}
$fstring = @file_get_contents(JAWS_DATA . "languages/{$lang}/plugins/{$lPlugin}");
$fstring = strtr($fstring, array($nstr => $nstr, $ostr => $nstr));
@file_put_contents(JAWS_DATA . "languages/{$lang}/plugins/{$lPlugin}", $fstring);
}
}
}
// others
foreach ($rootfiles as $rfile) {
if (file_exists(JAWS_DATA . "languages/{$lang}/{$rfile}")) {
$fstring = @file_get_contents(JAWS_DATA . "languages/{$lang}/{$rfile}");
$fstring = strtr($fstring, array($nstr => $nstr, $ostr => $nstr));
@file_put_contents(JAWS_DATA . "languages/{$lang}/{$rfile}", $fstring);
}
}
}
foreach ($_SESSION['upgrade']['stagedVersions'] as $stagedVersion) {
if (!$_SESSION['upgrade']['versions'][$stagedVersion]['status']) {
if ($_SESSION['upgrade']['stage'] < $_SESSION['upgrade']['versions'][$stagedVersion]['stage']) {
return true;
} else {
$_SESSION['upgrade']['stage']++;
}
} else {
$_SESSION['upgrade']['stage']++;
}
}
return true;
}
示例11: display
/**
* Displays image without saving and lose changes.
* This method adds the Content-type HTTP header
*
* @access public
* @param string $type Output format, default is the current used format
* @param int $quality Image quality, default is 75
* @param int $expires Set Cache-Control and Expires of HTTP header
* @return mixed True on success or a Jaws_Error object on error
*/
function display($type = '', $quality = null, $expires = 0)
{
if ($this->_readonly) {
$result = parent::display($type, $quality, $expires);
return $result;
}
$options = is_array($quality) ? $quality : array();
if (is_numeric($quality)) {
$options['quality'] = $quality;
}
$quality = $this->_getOption('quality', $options, 75);
$type = $type == 'jpg' ? 'jpeg' : $type;
$type = strtolower($type == '' ? $this->_itype : $type);
$type = empty($type) ? 'png' : $type;
if (!$this->_typeSupported($type, 'w')) {
return Jaws_Error::raiseError('Image type not supported for output.', __FUNCTION__);
}
if (!empty($expires)) {
header("Cache-Control: max-age=" . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
}
if (function_exists('imagealphablending')) {
imagealphablending($this->_hImage, false);
imagesavealpha($this->_hImage, true);
}
$funcName = 'image' . $type;
header('Content-type: ' . image_type_to_mime_type($this->get_image_extension_to_type($type)));
ob_start();
switch ($type) {
case 'jpeg':
$result = $funcName($this->_hImage, null, $quality);
break;
default:
$result = $funcName($this->_hImage);
}
$content = ob_get_contents();
ob_end_clean();
$this->free();
if (!$result) {
return Jaws_Error::raiseError('Couldn\'t display image', __FUNCTION__);
}
return $content;
}
示例12: UploadFiles
/**
* Upload Files
*
* @access public
* @param array $files $_FILES array
* @param string $dest destination directory(include end directory separator)
* @param string $allow_formats permitted file format
* @param bool $overwrite overwrite file or generate random filename
* null: random, true/false: overwrite?
* @param bool $move_files moving or only copying files. this param avail for non-uploaded files
* @param int $max_size max size of file
* @return mixed Returns uploaded files array on success or Jaws_Error/FALSE on failure
*/
static function UploadFiles($files, $dest, $allow_formats = '', $overwrite = true, $move_files = true, $max_size = null)
{
if (empty($files) || !is_array($files)) {
return false;
}
$result = array();
if (isset($files['tmp_name'])) {
$files = array($files);
}
$finfo = false;
if (extension_loaded('fileinfo')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// return mime type of file extension
}
$dest = rtrim($dest, "\\/") . DIRECTORY_SEPARATOR;
$allow_formats = array_filter(explode(',', $allow_formats));
foreach ($files as $key => $listFiles) {
if (!is_array($listFiles['tmp_name'])) {
$listFiles = array_map(create_function('$item', 'return array($item);'), $listFiles);
}
for ($i = 0; $i < count($listFiles['name']); ++$i) {
$file = array();
$file['name'] = $listFiles['name'][$i];
$file['tmp_name'] = $listFiles['tmp_name'][$i];
$file['size'] = $listFiles['size'][$i];
if (isset($listFiles['error'])) {
$file['error'] = $listFiles['error'][$i];
}
if (isset($file['error']) && !empty($file['error']) && $file['error'] != 4) {
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_UPLOAD_' . $file['error']), __FUNCTION__);
}
if (empty($file['tmp_name'])) {
continue;
}
$file['type'] = $finfo ? finfo_file($finfo, $file['tmp_name']) : '';
$user_filename = isset($file['name']) ? $file['name'] : '';
$host_filename = strtolower(preg_replace('/[^[:alnum:]_\\.\\-]/', '', $user_filename));
// remove deny_formats extension, even double extension
$host_filename = implode('.', array_diff(array_filter(explode('.', $host_filename)), self::$deny_formats));
$fileinfo = pathinfo($host_filename);
if (isset($fileinfo['extension'])) {
if (!empty($allow_formats) && !in_array($fileinfo['extension'], $allow_formats)) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $host_filename), __FUNCTION__);
}
$fileinfo['extension'] = '.' . $fileinfo['extension'];
} else {
$fileinfo['extension'] = '';
}
if (is_null($overwrite) || empty($fileinfo['filename'])) {
$host_filename = time() . mt_rand() . $fileinfo['extension'];
} elseif (!$overwrite && file_exists($dest . $host_filename)) {
$host_filename .= $fileinfo['filename'] . '_' . time() . mt_rand() . $fileinfo['extension'];
}
$uploadfile = $dest . $host_filename;
if (is_uploaded_file($file['tmp_name'])) {
if (!move_uploaded_file($file['tmp_name'], $uploadfile)) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $host_filename), __FUNCTION__);
}
} else {
// On windows-systems we can't rename a file to an existing destination,
// So we first delete destination file
if (file_exists($uploadfile)) {
@unlink($uploadfile);
}
$res = $move_files ? @rename($file['tmp_name'], $uploadfile) : @copy($file['tmp_name'], $uploadfile);
if (!$res) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $host_filename), __FUNCTION__);
}
}
// Check if the file has been altered or is corrupted
if (filesize($uploadfile) != $file['size']) {
@unlink($uploadfile);
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_CORRUPTED', $host_filename), __FUNCTION__);
}
Jaws_Utils::chmod($uploadfile);
$result[$key][$i]['user_filename'] = $user_filename;
$result[$key][$i]['host_filename'] = $host_filename;
$result[$key][$i]['host_filetype'] = $file['type'];
$result[$key][$i]['host_filesize'] = $file['size'];
}
}
return $result;
}
示例13: dropTable
/**
* drop an existing table via MDB2 management module
*
* @access public
* @param string $table name of table
* @return mixed MDB2_OK on success, a MDB2 error on failure
*/
function dropTable($table)
{
$this->dbc->loadModule('Manager');
$result = $this->dbc->manager->dropTable($this->getPrefix() . $table);
if (MDB2::isError($result)) {
if ($result->getCode() !== MDB2_ERROR_NOSUCHTABLE) {
return Jaws_Error::raiseError($result->getMessage(), $result->getCode(), JAWS_ERROR_ERROR, 1);
}
}
return true;
}
示例14: display
/**
* Displays image without saving and lose changes.
* This method adds the Content-type HTTP header
*
* @access public
* @param string $type Output format, default is the current used format
* @param int $quality Image quality, default is 75
* @param int $expires Set Cache-Control and Expires of HTTP header
* @return mixed True on success or a Jaws_Error object on error
*/
function display($type = '', $quality = null, $expires = 0)
{
if ($this->_readonly) {
$result = parent::display($type, $quality, $expires);
return $result;
}
$options = is_array($quality) ? $quality : array();
if (is_numeric($quality)) {
$options['quality'] = $quality;
}
$quality = $this->_getOption('quality', $options, 75);
try {
$this->_hImage->setImageCompression($quality);
} catch (ImagickException $error) {
return Jaws_Error::raiseError('Could not set image compression.', __FUNCTION__);
}
$type = $type == 'jpg' ? 'jpeg' : $type;
$type = strtolower($type == '' ? $this->_itype : $type);
$type = empty($type) ? 'png' : $type;
try {
$this->_hImage->setImageFormat($type);
} catch (ImagickException $error) {
return Jaws_Error::raiseError('Could not save image to file (conversion failed).', __FUNCTION__);
}
try {
$result = $this->_hImage->getImageBlob();
} catch (ImagickException $error) {
return Jaws_Error::raiseError('Could not display image.', __FUNCTION__);
}
if (!empty($expires)) {
header("Cache-Control: max-age=" . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
}
header('Content-type: ' . image_type_to_mime_type($this->get_image_extension_to_type($type)));
$this->free();
return $result;
}
示例15: rawPostData
/**
* Raw posts data to the URL
*
* @access public
* @param string $url URL address
* @param string $data Raw data
* @param string $response Response body
* @return mixed Response code on success, otherwise Jaws_Error
*/
function rawPostData($url, $data = '', &$response)
{
$this->httpRequest->reset($url, $this->options);
$this->httpRequest->addHeader('User-Agent', $this->user_agent);
$this->httpRequest->addHeader('Content-Type', $this->content_type);
$this->httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
// set post data
$this->httpRequest->setBody($data);
$result = $this->httpRequest->sendRequest();
if (PEAR::isError($result)) {
return Jaws_Error::raiseError($result->getMessage(), $result->getCode(), $this->default_error_level, 1);
}
$response = $this->httpRequest->getResponseBody();
return $this->httpRequest->getResponseCode();
}