本文整理汇总了PHP中Safe类的典型用法代码示例。如果您正苦于以下问题:PHP Safe类的具体用法?PHP Safe怎么用?PHP Safe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Safe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inputExists
public function inputExists( Safe $inputType = null, Safe $inputName, Safe $inputDefault = null ){
if( $inputType !== null ){
$inputType = $inputType->toString();
}
if( $inputDefault !== null ){
$inputDefault = $inputDefault->toString();
}
foreach( $this->_inputArray as $inputArray ){
if( $inputArray['inputType'] == $inputType && $inputArray['inputName'] == $inputName->toString() && $inputArray['inputDefault'] == $inputDefault ){
return true;
}
}
return false;
}
示例2: POST_emailAction
/**
* 通过邮箱找回密码
* @method POST_emailAction
* @author NewFuture
*/
public function POST_emailAction()
{
$response['status'] = 0;
if (!Input::post('email', $email, 'email')) {
$response['info'] = '邮箱格式有误或者不支持!';
} elseif (!Input::post('account', $account, Config::get('regex.account'))) {
$response['info'] = '学号格式有误!';
} elseif (!Safe::checkTry('pwd_email_' . $account)) {
$response['info'] = '尝试次数过多,临时封禁!';
} elseif (!($Printer = PrinterModel::where('account', $account)->field('id,email')->find())) {
$response['info'] = '尚未注册,或者账号错误';
} elseif (empty($Printer['email'])) {
$response['info'] = '未绑定邮箱,或邮箱不存在';
} elseif ($Printer['email'] != $email) {
$response['info'] = '绑定邮箱不一致,或者邮箱错误';
} elseif (!Mail::findPwd($email, $code = Random::code(6))) {
$response['info'] = '邮件发送出错,请联系我们!';
} else {
/*发送成功*/
$find = ['id' => $user['id'], 'account' => $account, 'code' => strtoupper($code)];
Session::set('find_info_p', $find);
Safe::del('pwd_email_' . $account);
$response['status'] = 1;
$response['info'] = '验证邮件已发送!';
}
$this->response = $response;
}
示例3: POST_emailAction
/**
* 通过邮箱找回密码
* @method POST_emailAction
* @author NewFuture
*/
public function POST_emailAction()
{
$response['status'] = 0;
if (!Input::post('email', $email, 'email')) {
$response['info'] = '邮箱格式有误或者不支持!';
} elseif (!Input::post('number', $number, 'card')) {
$response['info'] = '学号格式有误!';
} elseif (!Safe::checkTry('pwd_email_' . $number)) {
$response['info'] = '尝试次数过多,临时封禁!';
} elseif (!($user = UserModel::where('number', $number)->field('id,name,email')->find())) {
$response['info'] = '尚未注册,或者学号错误';
} elseif (empty($user['email'])) {
$response['info'] = '未绑定邮箱,或者学号错误';
} elseif (Encrypt::decryptEmail($user['email']) != $email) {
$response['info'] = '绑定邮箱不一致,或者邮箱错误';
} elseif (!Mail::findPwd($email, $code = Random::code(6), $user['name'])) {
$response['info'] = '邮件发送出错,请联系我们!';
} else {
/*发送成功*/
$findPwd = ['id' => $user['id'], 'number' => $number, 'code' => strtoupper($code)];
Session::set('find_info', $findPwd);
Safe::del('pwd_email_' . $number);
$response['status'] = 1;
$response['info'] = '找回验证码已发送到' . $email;
}
$this->response = $response;
}
示例4: indexAction
/**
* 登录注册验证
* @method indexAction
* @return [type] [description]
* @author NewFuture
*/
public function indexAction()
{
if (Input::post('number', $number, 'card') && Input::post('password', $password, 'trim')) {
Input::post('sch_id', $sch_id, 'int');
$safekey = $sch_id . 'auth_' . $number;
if (!Safe::checkTry($safekey, 5)) {
$this->response(0, '尝试次过度,账号临时封禁');
} elseif (Input::post('code', $code, 'ctype_alnum')) {
/*输入验证码直接验证*/
if ($this->verify($number, $password, $sch_id, $code)) {
/*验证通过*/
Safe::del($safekey);
} else {
$this->response(-1, '学校账号验证失败,请检查密码是否正确,您也可尝试登录该系统!');
}
} elseif ($result = $this->login($number, md5($password), $sch_id)) {
/*登录成功*/
Safe::del($safekey);
} elseif ($sch_id && false === $result) {
/*指定学校后登录失败*/
$this->response(-1, '登录失败!请检查学号和密码是否正确,或者找回密码!');
} elseif ($this->verify($number, $password, $sch_id)) {
/*验证成功*/
Safe::del($safekey);
} else {
/*注册验证失败*/
$this->response(-1, '验证出错,请检查学号或者密码是否正确!');
}
} else {
$this->response(-1, '学号或者密码无效!');
}
}
示例5: de
/**
* 通过Cookie_Key解密数据或数组
*
* @param $data
* @return array|string
*/
public function de($data)
{
if ($data === null) {
return $data;
}
return is_array($data) ? array_map(array($this, 'de'), $data) : Safe::decrypt($data, COOKIE_KEY);
}
示例6: check_file
function check_file($node)
{
global $context;
global $footprints;
$key = substr($node, strlen($context['path_to_root']));
// no extension to check
if (strpos($key, '.') === FALSE) {
} elseif (!strncmp($node, 'scripts/staging', 16)) {
} elseif (!strcmp($key, 'footprints.php')) {
} elseif (!strncmp(substr($key, -9), 'index.php', 9) && ($content = Safe::file_get_contents($node)) && !strcmp($content, Safe::mkdir_index_content())) {
} elseif (!strncmp($key, 'temporary/cache_i18n_locale_', 28)) {
} elseif (!strncmp(substr($key, -4), '.php', 4)) {
// one of the parameter files created by yacs
if (preg_match('/parameters\\/(agents|control|feeds|files|hooks|letters|root|scripts|services|skins|users|virtual_.+)\\.include\\.php$/i', $key)) {
} elseif (isset($footprints[$key])) {
$expected = $footprints[$key];
$actual = Scripts::hash($node);
if ($expected[0] != $actual[0] || $expected[1] != $actual[1]) {
$context['text'] .= sprintf(i18n::s('ERROR: File %s is missing or corrupted.'), $key) . BR . "\n";
}
} else {
$context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n";
}
// not a safe file
} elseif (!preg_match('/\\.(bak|bat|css|done|dtd|fdb|flv|gif|ico|jpeg|jpg|js|jsmin|htc|htm|html|mo|off|on|pdf|png|po|pot|reg|sh|sql|swf|tgz|txt|xml|zip)$/i', $key)) {
$context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n";
}
}
示例7: render
/**
* render graphviz object
*
* @return string the rendered text
**/
public function render($matches)
{
global $context;
list($text, $variant) = $matches;
// sanity check
if (!$text) {
$text = 'Hello->World!';
}
// remove tags put by WYSIWYG editors
$text = strip_tags(str_replace(array('>', '<', '&', '"', '\\"'), array('>', '<', '&', '"', '"'), str_replace(array('<br />', '</p>'), "\n", $text)));
// build the .dot content
switch ($variant) {
case 'digraph':
default:
$text = 'digraph G { ' . $text . ' }' . "\n";
break;
}
// id for this object
$hash = md5($text);
// path to cached files
$path = $context['path_to_root'] . 'temporary/graphviz.';
// we cache content
if ($content = Safe::file_get_contents($path . $hash . '.html')) {
return $content;
}
// build a .dot file
if (!Safe::file_put_contents($path . $hash . '.dot', $text)) {
$content = '[error writing .dot file]';
return $content;
}
// process the .dot file
if (isset($context['dot.command'])) {
$command = $context['dot.command'];
} else {
$command = 'dot';
}
// $font = '"/System/Library/Fonts/Times.dfont"';
// $command = '/sw/bin/dot -v -Nfontname='.$font
$command .= ' -Tcmapx -o "' . $path . $hash . '.map"' . ' -Tpng -o "' . $path . $hash . '.png"' . ' "' . $path . $hash . '.dot"';
if (Safe::shell_exec($command) == NULL) {
$content = '[error while using graphviz]';
return $content;
}
// produce the HTML
$content = '<img src="' . $context['url_to_root'] . 'temporary/graphviz.' . $hash . '.png" usemap="#mainmap" />';
$content .= Safe::file_get_contents($path . $hash . '.map');
// put in cache
Safe::file_put_contents($path . $hash . '.html', $content);
// done
return $content;
}
示例8: login
/**
* login
*
* The script checks provided name and password against remote server.
*
* This is done by transmitting the user name and the password
* while opening a FTP session to the server.
*
* @param string the nickname of the user
* @param string the submitted password
* @return TRUE on succesful authentication, FALSE othewise
*/
function login($name, $password)
{
global $context;
// we need some parameters
if (!isset($this->attributes['authenticator_parameters']) || !$this->attributes['authenticator_parameters']) {
Logger::error(i18n::s('Please provide parameters to the authenticator.'));
return FALSE;
}
// prepare network parameters
$server = $this->attributes['authenticator_parameters'];
if (strstr($server, ':')) {
list($server, $port) = explode(':', $server, 2);
} else {
$port = 21;
}
// open network socket
if (!($handle = Safe::fsockopen($server, $port))) {
Logger::error(sprintf(i18n::s('Impossible to connect to %.'), $this->attributes['authenticator_parameters']));
return FALSE;
}
// read welcome banner
if (!($line = fgets($handle, 256)) || !strstr($line, '2')) {
fclose($handle);
Logger::error(sprintf(i18n::s('Invalid banner message from %s.'), $this->attributes['authenticator_parameters']));
return FALSE;
}
// submit name
fputs($handle, "USER {$username}\r\n");
if (!($line = fgets($handle, 256)) || !strstr($line, '3')) {
fclose($handle);
Logger::error(sprintf(i18n::s('Impossible to submit name to %s.'), $this->attributes['authenticator_parameters']));
return FALSE;
}
// submit password
fputs($handle, "PASS {$password}\r\n");
if (!($line = fgets($handle, 256)) || !strstr($line, '2')) {
fclose($handle);
Logger::error(sprintf(i18n::s('Impossible to submit password to %s.'), $this->attributes['authenticator_parameters']));
return FALSE;
}
// close ftp session
fputs($handle, "QUIT\r\n");
fclose($handle);
// this is a valid user
return TRUE;
}
示例9: allow
/**
* check access rights
*
* @param string script name
* @paral string target anchor, if any
* @return boolean FALSE if access is denied, TRUE otherwise
*/
function allow($script, $anchor = NULL)
{
global $context;
// limit the scope of our check
if ($script != 'files/view.php' && $script != 'files/fetch.php' && $script != 'files/fetch_all.php' && $script != 'files/stream.php') {
return TRUE;
}
// sanity check
if (!$anchor) {
die(i18n::s('No anchor has been found.'));
}
// stop here if the agreement has been gathered previously
if (isset($_SESSION['agreements']) && is_array($agreements = $_SESSION['agreements'])) {
foreach ($agreements as $agreement) {
if ($agreement == $anchor) {
return TRUE;
}
}
}
// which agreement?
if (!$this->parameters) {
die(sprintf(i18n::s('No parameter has been provided to %s'), 'behaviors/agree_on_file_access'));
}
// do we have a related file to display?
if (!is_readable($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters)) {
die(sprintf(i18n::s('Bad parameter to behavior <code>%s %s</code>'), 'agree_on_file_access', $this->parameters));
}
// splash message
$context['text'] .= '<p class="agreement">' . i18n::s('Before moving forward, please read following text and express yourself at the end of the page.') . '</p><hr/>' . "\n";
// load and display the file to be displayed
$context['text'] .= Codes::beautify(Safe::file_get_contents($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters));
// target link to record agreement
if ($context['with_friendly_urls'] == 'Y') {
$agree_link = 'behaviors/agreements/agree.php/' . rawurlencode($anchor);
} else {
$agree_link = 'behaviors/agreements/agree.php?id=' . urlencode($anchor);
}
// display confirmation buttons at the end of the agreement
$context['text'] .= '<hr/><p class="agreement">' . i18n::s('Do you agree?');
$context['text'] .= ' ' . Skin::build_link($agree_link, i18n::s('Yes'), 'button');
$context['text'] .= ' ' . Skin::build_link('behaviors/agreements/deny.php', i18n::s('No'), 'button') . '</p>' . "\n";
// render the skin based only on text provided by this behavior
render_skin();
exit;
}
示例10: POST_indexAction
/**
* 打印店登录
* @method loginAction
* @return [type] [description]
* @author NewFuture
*/
public function POST_indexAction()
{
$response['status'] = 0;
if (!Input::post('account', $account, Config::get('regex.account'))) {
$response['info'] = '账号格式错误';
} elseif (!Input::post('password', $password, 'isMd5')) {
$response['info'] = '密码未加密处理';
} elseif (!Safe::checkTry('printer_auth_' . $account)) {
$response['info'] = '尝试次数过多账号临时封禁,稍后重试或者联系我们';
} elseif (!($Printer = PrinterModel::where('account', $account)->field('id,sch_id,password,status,name')->find())) {
$response['info'] = '账号错误';
} elseif (Encrypt::encryptPwd($password, $account) != $Printer['password']) {
$response['info'] = '密码错误';
} else {
Safe::del('printer_auth_' . $account);
unset($Printer['password']);
$sid = Session::start();
Session::set('printer', ['id' => $Printer['id'], 'sch_id' => $Printer['sch_id']]);
$response['status'] = 1;
$response['info'] = ['sid' => $sid, 'printer' => $Printer];
}
$this->response = $response;
}
示例11: validateDocumentPost
// build the form
$context['text'] .= Skin::build_form($fields);
// the submit button
$context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Send'), i18n::s('Press [s] to submit data'), 's') . '</p>' . "\n";
// end of the form
$context['text'] .= '</div></form>';
// the script used for form handling at the browser
Page::insert_script('func' . 'tion validateDocumentPost(container) {' . "\n" . ' // letter_title is mandatory' . "\n" . ' if(!container.letter_title.value) {' . "\n" . ' alert("' . i18n::s('No title has been provided.') . '");' . "\n" . ' Yacs.stopWorking();' . "\n" . ' return false;' . "\n" . ' }' . "\n" . ' return true;' . "\n" . '}' . "\n" . "\n" . 'document.main_form.letter_title.focus();' . "\n");
// no mail in demo mode
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' && file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.'));
// handle posted data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
// ensure all letters will be sent even if the browser connection dies
Safe::ignore_user_abort(TRUE);
// always archive the letter
$anchor = Sections::lookup('letters');
// no section yet, create one
if (!$anchor) {
$context['text'] .= i18n::s('Creating a section for archived letters') . BR . "\n";
$fields['nick_name'] = 'letters';
$fields['title'] = i18n::c('Archived letters');
$fields['introduction'] = i18n::c('To remember our previous messages');
$fields['description'] = i18n::c('YACS puts automatically sent letters into this section.');
$fields['locked'] = 'Y';
// no direct contributions
$fields['index_map'] = 'N';
// listed only to associates
$fields['rank'] = 30000;
// at the end of the list
示例12: elseif
} elseif (!$permitted) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// deletion is confirmed
} elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') {
// touch the related anchor before actual deletion, since the table has to be accessible at that time
if (is_object($anchor)) {
$anchor->touch('table:delete', $item['id']);
}
// delete and go back to the anchor or to the index page
if (Tables::delete($item['id'])) {
Tables::clear($item);
if (is_object($anchor)) {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url());
} else {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'articles/');
}
}
// deletion has to be confirmed
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
Logger::error(i18n::s('The action has not been confirmed.'));
} else {
// commands
$menu = array();
$menu[] = Skin::build_submit_button(i18n::s('Yes, I want to delete this table'), NULL, NULL, 'confirmed');
if (is_object($anchor)) {
$menu[] = Skin::build_link($anchor->get_url(), i18n::s('Cancel'), 'span');
}
// the submit button
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . "\n" . Skin::finalize_list($menu, 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="confirm" value="yes" />' . "\n" . '</p></form>' . "\n";
// set the focus
示例13: encode
/**
* encode a sequence of HTML tags, or plain text, to PDF
*
* @param string the text to append
* @return the content of PDF
* @see articles/fetch_as_pdf.php
*/
function encode($text)
{
global $context;
//
// meta information
//
// encode it to iso8859 -- sorry
// document title
if ($context['page_title']) {
$this->SetTitle(utf8::to_iso8859(Safe::html_entity_decode($context['page_title'], ENT_COMPAT, 'ISO-8859-15')));
}
// document author
if ($context['page_author']) {
$this->SetAuthor(utf8::to_iso8859(Safe::html_entity_decode($context['page_author'], ENT_COMPAT, 'ISO-8859-15')));
}
// document subject
if ($context['subject']) {
$this->SetSubject(utf8::to_iso8859(Safe::html_entity_decode($context['subject'], ENT_COMPAT, 'ISO-8859-15')));
}
// document creator (typically, the tool used to produce the document)
$this->SetCreator('yacs');
//
// PDF content
//
// start the rendering engine
$this->AliasNbPages();
$this->AddPage();
$this->SetFont('Arial', 'B', 16);
// reference view.php instead of ourself to achieve correct links
$text = str_replace('/fetch_as_pdf.php', '/view.php', $text);
// remove all unsupported tags
$text = strip_tags($text, "<a><b><blockquote><br><code><div><em><font><h1><h2><h3><h4><hr><i><img><li><p><pre><strong><table><tr><tt><u><ul>");
// spaces instead of carriage returns
$text = str_replace("\n", ' ', $text);
// transcode to ISO8859-15 characters
$text = utf8::to_iso8859(Safe::html_entity_decode($text, ENT_COMPAT, 'ISO-8859-15'));
// locate every HTML/XML tag
$areas = preg_split('/<(.*)>/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$height = 5;
$link = '';
foreach ($areas as $index => $entity) {
// a tag entity
if ($index % 2) {
@(list($tag, $attributes) = explode(' ', $entity, 2));
switch (strtolower($tag)) {
case 'a':
if (preg_match('/href="(.*)"/i', $attributes, $matches)) {
$link = $matches[1];
// suppress local references (eg, in table of content)
if (preg_match('/(#.*)/', $link)) {
$link = '';
} elseif ($link[0] == '/') {
$link = $context['url_to_home'] . $link;
}
}
break;
case 'b':
$this->SetFont('', 'B');
break;
case '/b':
$this->SetFont('', '');
break;
case 'blockquote':
$this->Ln($height);
break;
case '/blockquote':
$this->Ln($height);
break;
case 'br':
$this->Ln($height);
break;
case 'code':
$this->SetFont('Courier', '', 11);
$this->SetFontSize(11);
break;
case '/code':
$this->SetFont('Times', '', 12);
$this->SetFontSize(12);
break;
case 'div':
case '/div':
$this->Ln($height);
break;
case 'em':
$this->SetFont('', 'I');
break;
case '/em':
$this->SetFont('', '');
break;
case 'font':
if (preg_match('/color="#(.{6})"/i', $attributes, $matches)) {
$color = $matches[1];
$r = hexdec($color[0] . $color[1]);
//.........这里部分代码省略.........
示例14: while
$context['text'] .= Skin::build_block(sprintf(i18n::s('Analyzing table %s...'), SQL::table_name('comments')), 'title');
// scan up to 20000 items
$count = 0;
$query = "SELECT id, anchor FROM " . SQL::table_name('comments') . " ORDER BY anchor LIMIT 0, 100000";
if (!($result = SQL::query($query))) {
return;
} else {
// fetch one anchor and the linked member
$errors_count = 0;
while ($row = SQL::fetch($result)) {
// animate user screen and take care of time
$count++;
if (!($count % 500)) {
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
// ensure enough execution time
Safe::set_time_limit(30);
}
// check that the anchor exists, if any
if ($row['anchor'] && !Anchors::get($row['anchor'])) {
$context['text'] .= sprintf(i18n::s('Orphan: %s'), 'comment ' . Skin::build_link(Comments::get_url($row['id']), $row['id'])) . BR . "\n";
if (++$errors_count >= 5) {
$context['text'] .= i18n::s('Too many successive errors. Aborted') . BR . "\n";
break;
}
} else {
$errors_count = 0;
}
}
}
// ending message
$context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
示例15: natsort
}
if ($file == 'index.php') {
continue;
}
if ($file == 'behavior.php') {
continue;
}
if ($file == 'behaviors.php') {
continue;
}
if (!preg_match('/(.*)\\.php$/i', $file, $matches)) {
continue;
}
$behaviors[] = $matches[1];
}
Safe::closedir($dir);
if (@count($behaviors)) {
natsort($behaviors);
foreach ($behaviors as $behavior) {
$context['text'] .= '<li>' . $behavior . "</li>\n";
}
}
}
$context['text'] .= '</ul>';
// how to use behaviors
if (Surfer::is_associate()) {
$context['text'] .= '<p>' . sprintf(i18n::s('For example, if you want to apply the behavior <code>foo</code>, go to the %s , and select a target section, or add a new one.'), Skin::build_link('sections/', i18n::s('site map'), 'shortcut')) . '</p>' . '<p>' . i18n::s('In the form used to edit the section, type the keyword <code>foo</code> in the behavior field, then save changes.') . '</p>';
}
// referrals, if any
$context['components']['referrals'] =& Skin::build_referrals('behaviors/index.php');
// render the skin