本文整理汇总了PHP中Jaws_Utils类的典型用法代码示例。如果您正苦于以下问题:PHP Jaws_Utils类的具体用法?PHP Jaws_Utils怎么用?PHP Jaws_Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jaws_Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Backup
/**
* Returns downloadable backup file
*
* @access public
* @return void
*/
function Backup()
{
$this->gadget->CheckPermission('Backup');
$tmpDir = sys_get_temp_dir();
$domain = preg_replace("/^(www.)|(:{$_SERVER['SERVER_PORT']})\$|[^a-z0-9\\-\\.]/", '', strtolower($_SERVER['HTTP_HOST']));
$nameArchive = $domain . '-' . date('Y-m-d') . '.tar.gz';
$pathArchive = $tmpDir . DIRECTORY_SEPARATOR . $nameArchive;
//Dump database data
$dbFileName = 'dbdump.xml';
$dbFilePath = $tmpDir . DIRECTORY_SEPARATOR . $dbFileName;
Jaws_DB::getInstance()->Dump($dbFilePath);
$files = array();
require_once PEAR_PATH . 'File/Archive.php';
$files[] = File_Archive::read(JAWS_DATA);
$files[] = File_Archive::read($dbFilePath, $dbFileName);
File_Archive::extract($files, File_Archive::toArchive($pathArchive, File_Archive::toFiles()));
Jaws_Utils::Delete($dbFilePath);
// browser must download file from server instead of cache
header("Expires: 0");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// force download dialog
header("Content-Type: application/force-download");
// set data type, size and filename
header("Content-Disposition: attachment; filename=\"{$nameArchive}\"");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . @filesize($pathArchive));
@readfile($pathArchive);
Jaws_Utils::Delete($pathArchive);
}
示例2: image
/**
* Displays the captcha image
*
* @access public
* @param int $key Captcha key
* @return mixed Captcha raw image data
*/
function image($key)
{
$value = Jaws_Utils::RandomText();
$result = $this->update($key, $value);
if (Jaws_Error::IsError($result)) {
$value = '';
}
$bg = dirname(__FILE__) . '/resources/simple.bg.png';
$im = imagecreatefrompng($bg);
imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
// Write it in a random position..
$darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
$x = 5;
$y = 20;
$text_length = strlen($value);
for ($i = 0; $i < $text_length; $i++) {
$fnt = rand(7, 10);
$y = rand(6, 10);
imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
$x = $x + rand(15, 25);
}
header("Content-Type: image/png");
ob_start();
imagepng($im);
$content = ob_get_contents();
ob_end_clean();
imagedestroy($im);
return $content;
}
示例3: Run
/**
* Does any actions required to finish the stage.
*
* @access public
* @return bool|Jaws_Error Either true on success, or a Jaws_Error
* containing the reason for failure.
*/
function Run()
{
$cleanup_error = false;
$cleanup_items = @file_get_contents(JAWS_PATH . 'upgrade/stages/Cleanup/folders.txt');
$cleanup_items = array_filter(explode("\n", $cleanup_items));
foreach ($cleanup_items as $item) {
if (file_exists(JAWS_PATH . $item)) {
if (!Jaws_Utils::Delete(JAWS_PATH . $item)) {
$cleanup_error = true;
}
}
}
$cleanup_items = @file_get_contents(JAWS_PATH . 'upgrade/stages/Cleanup/files.txt');
$cleanup_items = array_filter(explode("\n", $cleanup_items));
foreach ($cleanup_items as $item) {
if (file_exists(JAWS_PATH . $item)) {
if (!Jaws_Utils::Delete(JAWS_PATH . $item)) {
$cleanup_error = true;
}
}
}
if ($cleanup_error) {
return Jaws_Error::raiseError(_t('UPGRADE_CLEANUP_ERROR_PERMISSION'), 0, JAWS_ERROR_WARNING);
}
return true;
}
示例4: ShowNoPermission
/**
* Builds the NoPermission UI
*
* @access public
* @param string $user Username
* @param string $gadget The Gadget user is requesting
* @param string $action The 'denied' action
* @return string XHTML content
*/
function ShowNoPermission($user, $gadget, $action)
{
// Load the template
$tpl = $this->gadget->template->load('NoPermission.html');
$tpl->SetBlock('NoPermission');
$tpl->SetVariable('nopermission', _t('USERS_NO_PERMISSION_TITLE'));
$tpl->SetVariable('description', _t('USERS_NO_PERMISSION_DESC', $gadget, $action));
$tpl->SetVariable('admin_script', BASE_SCRIPT);
$tpl->SetVariable('site-name', $this->gadget->registry->fetch('site_name', 'Settings'));
$tpl->SetVariable('site-slogan', $this->gadget->registry->fetch('site_slogan', 'Settings'));
$tpl->SetVariable('BASE_URL', $GLOBALS['app']->GetSiteURL('/'));
$tpl->SetVariable('.dir', _t('GLOBAL_LANG_DIRECTION') == 'rtl' ? '.rtl' : '');
if ($GLOBALS['app']->Session->Logged()) {
$tpl->SetBlock('NoPermission/known');
$logoutLink = $this->gadget->urlMap('Logout');
$referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']);
$tpl->SetVariable('known_description', _t('USERS_NO_PERMISSION_KNOWN_DESC', $logoutLink, $referLink));
$tpl->ParseBlock('NoPermission/known');
} else {
$tpl->SetBlock('NoPermission/anon');
$loginLink = $this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(false))));
$referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']);
$tpl->SetVariable('anon_description', _t('USERS_NO_PERMISSION_ANON_DESC', $loginLink, $referLink));
$tpl->ParseBlock('NoPermission/anon');
}
$tpl->ParseBlock('NoPermission');
return $tpl->Get();
}
示例5: Install
/**
* Install the gadget
*
* @access public
* @param string $input_schema Schema file path
* @param array $input_variables Schema variables
* @return mixed True on success or Jaws_Error on failure
*/
function Install($input_schema = '', $input_variables = array())
{
if (!Jaws_Utils::is_writable(JAWS_DATA)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA));
}
$new_dir = JAWS_DATA . 'phoo' . DIRECTORY_SEPARATOR;
if (!Jaws_Utils::mkdir($new_dir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir));
}
$result = $this->installSchema('schema.xml');
if (Jaws_Error::IsError($result)) {
return $result;
}
$result = $this->installSchema('insert.xml', null, 'schema.xml', true);
if (Jaws_Error::IsError($result)) {
return $result;
}
if (!empty($input_schema)) {
$result = $this->installSchema($input_schema, $input_variables, 'schema.xml', true);
if (Jaws_Error::IsError($result)) {
return $result;
}
}
// Install listener for update comment
$this->gadget->event->insert('UpdateComment');
return true;
}
示例6: Display
/**
* Builds the upgader page.
*
* @access public
* @return string A block of valid XHTML to display an introduction and form.
*/
function Display()
{
$tpl = new Jaws_Template(false, false);
$tpl->Load('display.html', 'stages/Introduction/templates');
$tpl->SetBlock('Introduction');
$tpl->SetVariable('welcome', _t('UPGRADE_INTRO_WELCOME'));
$tpl->SetVariable('title_info', _t('UPGRADE_INTRO_UPGRADER'));
$tpl->SetVariable('db_info', _t('UPGRADE_INTRO_DATABASE'));
$tpl->SetVariable('ftp_info', _t('UPGRADE_INTRO_FTP'));
$tpl->SetVariable('language', _t('GLOBAL_LANGUAGE'));
$tpl->SetVariable('next', _t('GLOBAL_NEXT'));
if (is_writable(JAWS_PATH . 'data/logs') && is_dir(JAWS_PATH . 'data/logs')) {
$tpl->SetVariable('log_use', _t('UPGRADE_INTRO_LOG', 'data/logs/upgrade.txt'));
$tpl->SetBlock('Introduction/logcheckbox');
$tpl->ParseBlock('Introduction/logcheckbox');
} else {
$tpl->SetVariable('log_use', _t('UPGRADE_INTRO_LOG_ERROR', 'data/logs'));
}
$langs = Jaws_Utils::GetLanguagesList();
$selected_lang = isset($_SESSION['upgrade']['language']) ? $_SESSION['upgrade']['language'] : 'en';
foreach ($langs as $code => $fullname) {
$tpl->SetBlock('Introduction/lang');
$tpl->SetVariable('selected', $code == $selected_lang ? 'selected="selected"' : '');
$tpl->SetVariable('code', $code);
$tpl->SetVariable('fullname', $fullname);
$tpl->ParseBlock('Introduction/lang');
}
$tpl->ParseBlock('Introduction');
return $tpl->Get();
}
示例7: Jaws_Template
/**
* Class constructor
*
* @access public
* @param bool $loadFromTheme Try to load template from theme
* @param bool $loadGlobalVariables Fetch and set global variables
* @return void
*/
function Jaws_Template($loadFromTheme = false, $loadGlobalVariables = true)
{
$this->IdentifierRegExp = '[\\.[:digit:][:lower:]_-]+';
$this->BlockRegExp = '@<!--\\s+begin\\s+(' . $this->IdentifierRegExp . ')\\s+([^>]*)-->(.*)<!--\\s+end\\s+\\1\\s+-->@sim';
$this->VarsRegExp = '@{{\\s*(' . $this->IdentifierRegExp . ')\\s*}}@sim';
$this->IsBlockRegExp = '@##\\s*(' . $this->IdentifierRegExp . ')\\s*##@sim';
$namexp = '[[:digit:][:lower:]_]+';
$this->NewBlockRegExp = '@<!--\\s+begin\\s+(' . $namexp . ')\\s+' . '(?:if\\((!)?(' . $namexp . ')\\)\\s+|)' . '(?:loop\\((' . $namexp . ')\\)\\s+|)' . '-->(.*)<!--\\s+end\\s+\\1\\s+-->@sim';
$this->globalVariables['theme_url'] = '';
$this->globalVariables['.dir'] = _t('GLOBAL_LANG_DIRECTION') == 'rtl' ? '.rtl' : '';
$this->globalVariables['base_url'] = Jaws_Utils::getBaseURL('/');
$this->globalVariables['requested_url'] = Jaws_Utils::getRequestURL();
$this->globalVariables['base_script'] = BASE_SCRIPT;
if ($loadGlobalVariables) {
$this->loadFromTheme = $loadFromTheme;
$this->theme = $GLOBALS['app']->GetTheme();
$layout = $GLOBALS['app']->Layout->GetLayoutName() . '/';
$this->layout = @is_dir($this->theme['path'] . $layout) ? $layout : '';
$browser = $GLOBALS['app']->GetBrowserFlag();
$this->globalVariables['theme_url'] = $this->theme['url'];
$this->globalVariables['data_url'] = $GLOBALS['app']->getDataURL();
$this->globalVariables['.browser'] = empty($browser) ? '' : ".{$browser}";
$this->globalVariables['main_index'] = $GLOBALS['app']->mainIndex ? 'index' : '';
$this->globalVariables['main_gadget'] = strtolower($GLOBALS['app']->mainGadget);
$this->globalVariables['main_action'] = strtolower($GLOBALS['app']->mainAction);
} else {
$this->loadFromTheme = false;
}
}
示例8: Get
/**
*
*/
function Get($email, $name)
{
$ap_dir = JAWS_DATA . 'cache' . DIRECTORY_SEPARATOR . 'addressprotector';
if (file_exists($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name))) {
$contents = file_get_contents($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name));
$contents = '<a href="http://address-protector.com/' . $contents . '">' . $name . '</a>';
return $contents;
}
Jaws_Utils::mkdir($ap_dir);
if (!is_dir($ap_dir) || !Jaws_Utils::is_writable($ap_dir) || !(bool) ini_get('allow_url_fopen')) {
$contents = str_replace(array('@', '.'), array('(at)', 'dot'), $email);
return $contents;
}
$url = "http://address-protector.com/?mode=textencrypt&name=<name>&email=<email>";
$url = str_replace('<name>', urlencode($name), $url);
$url = str_replace('<email>', $email, $url);
$contents = $this->getURL($url);
if (empty($contents)) {
$contents = str_replace(array('@', '.'), array('(at)', 'dot'), $email);
}
if (substr($contents, -1, 1) == "\n") {
$contents = substr($contents, 0, -1);
}
file_put_contents($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name), $contents);
$contents = '<a href="http://address-protector.com/' . $contents . '">' . $name . '</a>';
return $contents;
}
示例9: Attachment
/**
* Download post attachment
*
* @access public
* @return string Requested file content or HTML error page
*/
function Attachment()
{
$rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'attach'), 'get');
$pModel = $this->gadget->model->load('Posts');
$post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']);
if (Jaws_Error::IsError($post)) {
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
$aModel = $this->gadget->model->load('Attachments');
$attachment = $aModel->GetAttachmentInfo($rqst['attach']);
if (Jaws_Error::IsError($attachment)) {
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
if (!empty($attachment)) {
$filepath = JAWS_DATA . 'forums/' . $attachment['filename'];
if (file_exists($filepath)) {
// increase download hits
$result = $aModel->HitAttachmentDownload($rqst['attach']);
if (Jaws_Error::IsError($result)) {
// do nothing
}
if (Jaws_Utils::Download($filepath, $attachment['title'])) {
return;
}
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(500);
}
}
$this->SetActionMode('Attachment', 'normal', 'standalone');
return Jaws_HTTPError::Get(404);
}
示例10: packTheme
/**
* Creates a .zip file of the theme in themes/ directory
*
* @access public
* @param string $theme Name of the theme
* @param string $srcDir Source directory
* @param string $destDir Target directory
* @param bool $copy_example_to_repository If copy example.png too or not
* @return bool Returns true if:
* - Theme exists
* - Theme exists and could be packed
* Returns false if:
* - Theme doesn't exist
* - Theme doesn't exists and couldn't be packed
*/
function packTheme($theme, $srcDir, $destDir, $copy_example_to_repository = true)
{
$themeSrc = $srcDir . '/' . $theme;
if (!is_dir($themeSrc)) {
return new Jaws_Error(_t('TMS_ERROR_THEME_DOES_NOT_EXISTS', $theme));
}
if (!Jaws_Utils::is_writable($destDir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $destDir), $this->gadget->name);
}
$themeDest = $destDir . '/' . $theme . '.zip';
//If file exists.. delete it
if (file_exists($themeDest)) {
@unlink($themeDest);
}
require_once PEAR_PATH . 'File/Archive.php';
$reader = File_Archive::read($themeSrc, $theme);
$innerWriter = File_Archive::toFiles();
$writer = File_Archive::toArchive($themeDest, $innerWriter);
$res = File_Archive::extract($reader, $writer);
if (PEAR::isError($res)) {
return new Jaws_Error(_t('TMS_ERROR_COULD_NOT_PACK_THEME'));
}
Jaws_Utils::chmod($themeDest);
if ($copy_example_to_repository) {
//Copy image to repository/images
if (file_exists($srcDir . '/example.png')) {
@copy($srcDir . '/example.png', JAWS_DATA . "themes/repository/Resources/images/{$theme}.png");
Jaws_Utils::chmod(JAWS_DATA . 'themes/repository/Resources/images/' . $theme . '.png');
}
}
return $themeDest;
}
示例11: Display
/**
* Displays the emblems
*
* @access public
* @return string XHTML UI
*/
function Display()
{
$tpl = $this->gadget->template->load('Emblems.html');
$tpl->SetBlock('emblems');
$tpl->SetVariable('title', _t('EMBLEMS_ACTION_TITLE'));
$model = $this->gadget->model->load('Emblems');
$emblems = $model->GetEmblems(true);
if (!Jaws_Error::IsError($emblems)) {
$site = urlencode(Jaws_Utils::getBaseURL('/', false));
$page = urlencode(Jaws_Utils::getRequestURL(false));
$name = urlencode($this->gadget->registry->fetch('site_name', 'Settings'));
$slogan = urlencode($this->gadget->registry->fetch('site_slogan', 'Settings'));
$title = $GLOBALS['app']->Layout->GetTitle();
foreach ($emblems as $e) {
$e['url'] = str_replace(array('{url}', '{base_url}', '{requested_url}', '{site_name}', '{site_slogan}', '{title}'), array($page, $site, $page, $name, $slogan, $title), $e['url']);
$tpl->SetBlock('emblems/emblem');
$tpl->SetVariable('id', $e['id']);
$tpl->SetVariable('title', _t('EMBLEMS_TYPE_' . $e['type'], $e['title']));
$tpl->SetVariable('image', $GLOBALS['app']->getDataURL('emblems/' . $e['image']));
$tpl->SetVariable('url', $e['url']);
$tpl->ParseBlock('emblems/emblem');
}
}
$tpl->ParseBlock('emblems');
return $tpl->Get();
}
示例12: saveFile
/**
* Saves data into the file
*
* @access public
* @param string $cache_file
* @param string $data
* @return mixed True on success and PEAR error on failure
*/
function saveFile($cache_file, $data)
{
if (!Jaws_Utils::file_put_contents($cache_file, serialize($data))) {
return PEAR::raiseError("Fail to save stream with file_put_contents('{$cache_file}',...).");
}
return true;
}
示例13: Execute
/**
* Event execute method
*
*/
function Execute($shouter, $code)
{
$reqURL = Jaws_Utils::getRequestURL(true);
$uModel = $this->gadget->model->loadAdmin('ErrorMaps');
$res = $uModel->GetHTTPError($reqURL, $code);
if (!Jaws_Error::IsError($res) && !empty($res) && ($res['code'] == 301 || $res['code'] == 302)) {
Jaws_Header::Location($res['url'], $res['code']);
}
return $res;
}
示例14: UpdateAccount
/**
* Updates user account information
*
* @access public
* @return void
*/
function UpdateAccount()
{
if (!$GLOBALS['app']->Session->Logged()) {
Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true)))));
}
$this->gadget->CheckPermission('EditUserName,EditUserNickname,EditUserEmail,EditUserPassword', '', false);
$post = jaws()->request->fetch(array('username', 'nickname', 'email', 'password', 'chkpassword'), 'post');
if ($post['password'] === $post['chkpassword']) {
// check edit username permission
if (empty($post['username']) || !$this->gadget->GetPermission('EditUserName')) {
$post['username'] = $GLOBALS['app']->Session->GetAttribute('username');
}
// check edit nickname permission
if (empty($post['nickname']) || !$this->gadget->GetPermission('EditUserNickname')) {
$post['nickname'] = $GLOBALS['app']->Session->GetAttribute('nickname');
}
// check edit email permission
if (empty($post['email']) || !$this->gadget->GetPermission('EditUserEmail')) {
$post['email'] = $GLOBALS['app']->Session->GetAttribute('email');
}
// set new email
$post['new_email'] = '';
if ($post['email'] != $GLOBALS['app']->Session->GetAttribute('email')) {
$post['new_email'] = $post['email'];
$post['email'] = $GLOBALS['app']->Session->GetAttribute('email');
}
// check edit password permission
if (empty($post['password']) || !$this->gadget->GetPermission('EditUserPassword')) {
$post['password'] = null;
}
$model = $this->gadget->model->load('Account');
$result = $model->UpdateAccount($GLOBALS['app']->Session->GetAttribute('user'), $post['username'], $post['nickname'], $post['email'], $post['new_email'], $post['password']);
// unset unnecessary account data
unset($post['password'], $post['chkpassword']);
if (!Jaws_Error::IsError($result)) {
$message = _t('USERS_MYACCOUNT_UPDATED');
if (!empty($post['new_email'])) {
$mResult = $this->ReplaceEmailNotification($GLOBALS['app']->Session->GetAttribute('user'), $post['username'], $post['nickname'], $post['new_email'], $post['email']);
if (Jaws_Error::IsError($mResult)) {
$message = $message . "\n" . $mResult->getMessage();
} else {
$message = $message . "\n" . _t('USERS_EMAIL_REPLACEMENT_SENT');
}
}
$GLOBALS['app']->Session->PushResponse($message, 'Users.Account.Response');
} else {
$GLOBALS['app']->Session->PushResponse($result->GetMessage(), 'Users.Account.Response', RESPONSE_ERROR, $post);
}
} else {
// unset unnecessary account data
unset($post['password'], $post['chkpassword']);
$GLOBALS['app']->Session->PushResponse(_t('USERS_USERS_PASSWORDS_DONT_MATCH'), 'Users.Account.Response', RESPONSE_ERROR, $post);
}
Jaws_Header::Location($this->gadget->urlMap('Account'));
}
示例15: Install
/**
* Installs the gadget
*
* @access public
* @return mixed True on successful installation, Jaws_Error otherwise
*/
function Install()
{
$result = $this->installSchema('schema.xml');
if (Jaws_Error::IsError($result)) {
return $result;
}
$new_dir = JAWS_DATA . 'directory';
if (!Jaws_Utils::mkdir($new_dir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir));
}
return true;
}