本文整理汇总了PHP中Security::htmlentities方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::htmlentities方法的具体用法?PHP Security::htmlentities怎么用?PHP Security::htmlentities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security::htmlentities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_htmlentities_double_encode
/**
* Tests Security::htmlentities()
*
* @test
*/
public function test_htmlentities_double_encode()
{
$output = Security::htmlentities('"H&M"');
$output = Security::htmlentities($output);
$expected = '"H&M"';
$this->assertEquals($expected, $output);
}
示例2: displayForm
/**
* Renders the field's form element for editing in the admin site
*/
public static function displayForm($value, &$settings, $model)
{
$class = get_called_class();
$settings = static::settings($settings);
$include_label = isset($settings['label']) ? $settings['label'] : true;
$required = isset($settings['required']) ? $settings['required'] : false;
$errors = $model->getErrorsForField($settings['mapping']['fieldName']);
$has_errors = count($errors) > 0;
$input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge');
if (!isset($input_attributes['id'])) {
$input_attributes['id'] = 'form_' . $settings['mapping']['fieldName'];
}
$attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings));
$label_text = $settings['title'] . ($required ? ' *' : '');
if (empty($value)) {
$value = substr(\Security::generate_token(), 0, 16);
}
// Description?
$description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : '';
// Build the input
$input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />';
// Build the label
$label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : ''));
// Don't wrap the input if wrap is set to false
if (isset($settings['wrap']) && $settings['wrap'] === false) {
return $label . $input;
}
return html_tag('div', $attributes, $label . $description . $input);
}
示例3: displayForm
/** inheritdoc */
public static function displayForm($value, &$settings, $model)
{
$class = get_called_class();
$settings = static::settings($settings);
$include_label = isset($settings['label']) ? $settings['label'] : true;
$required = isset($settings['required']) ? $settings['required'] : false;
$errors = $model->getErrorsForField($settings['mapping']['fieldName']);
$has_errors = count($errors) > 0;
$input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge form-control');
if (!isset($input_attributes['id'])) {
$input_attributes['id'] = 'form_' . $settings['mapping']['fieldName'];
}
$attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings));
$label_text = $settings['title'] . ($required ? ' *' : '');
// Build the input
$input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />';
// Build the label
$label = !$include_label ? '' : \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label'));
// Wrap it in an input group
$input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), ' '));
// Don't wrap the input if wrap is set to false
if (isset($settings['wrap']) && $settings['wrap'] === false) {
return $label . $input;
}
return html_tag('div', $attributes, $label . $input);
}
示例4: displayForm
/**
* Renders the field's form element for editing in the admin site
* @see \Admin::getFieldSettings()
* @param mixed $value The current value of the property, if there is one
* @param array $settings Field settings, created through \Admin::getFieldSettings()
* @param object $model The model, if it is being edited.
* @return string The form control
*/
public static function displayForm($value, &$settings, $model)
{
$class = get_called_class();
$settings = static::settings($settings);
$include_label = isset($settings['label']) ? $settings['label'] : true;
$required = isset($settings['required']) ? $settings['required'] : false;
$errors = $model->getErrorsForField($settings['mapping']['fieldName']);
$has_errors = count($errors) > 0;
$input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge');
if (!isset($input_attributes['id'])) {
$input_attributes['id'] = 'form_' . $settings['mapping']['fieldName'];
}
$attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings));
$label_text = $settings['title'] . ($required ? ' *' : '');
// Translation?
if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) {
// If there is no translation
if (!$model->hasTranslation($settings['mapping']['columnName'])) {
$attributes['class'] .= ' no-translation';
$input_attributes['class'] .= ' no-translation';
$label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text;
} else {
$label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text;
}
}
// Description?
$description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : '';
// Build the input
$input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />';
// Build the label
$label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : ''));
// Prepend or append things...
if (isset($settings['prepend'])) {
$input = html_tag('div', array('class' => 'input-prepend'), html_tag('span', array('class' => 'add-on'), $settings['prepend']) . $input);
}
if (isset($settings['append'])) {
$input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), $settings['append']));
}
// Don't wrap the input if wrap is set to false
if (isset($settings['wrap']) && $settings['wrap'] === false) {
return $label . $input;
}
// Add the 'keep updated' control if the field has a template
if (isset($settings['template']) && !empty($settings['template'])) {
$attributes['class'] .= ' field-with-controls field-with-template';
$auto_update_setting = 'settings[' . $settings['mapping']['fieldName'] . '][auto_update]';
$auto_update_content = \Form::hidden($auto_update_setting, '0', array()) . html_tag('label', array('class' => 'checkbox auto-update-label'), \Form::checkbox($auto_update_setting, '1', \Arr::get($settings, 'auto_update', true), array('class' => 'auto-update')) . strtolower(\Lang::get('admin.common.auto_update')));
$auto_update = html_tag('div', array('class' => 'controls-top'), $auto_update_content);
$label .= $auto_update;
return array('content' => html_tag('div', $attributes, $label . $description . $input) . '<div class="clear"><!-- --></div>', 'widget' => false, 'assets' => array('js' => array('/admin/assets/js/twig.min.js', '/admin/assets/js/fields/template.js')), 'js_data' => $settings);
}
return html_tag('div', $attributes, $label . $description . $input);
}
示例5: strim
function strim($string, $width = 0, $trimmarker = null, $is_html = true, $is_remove_line_feed = false)
{
if (!$width) {
return $string;
}
if (is_null($trimmarker)) {
$trimmarker = '...';
}
if ($is_remove_line_feed) {
$string = str_replace(array("\r", "\n"), '', $string);
}
$original_width = mb_strlen($string);
if ($is_html) {
$string = Site_Util::html_entity_decode($string);
}
$string = mb_strimwidth($string, 0, $width, $trimmarker);
if ($is_html) {
$string = Security::htmlentities($string);
}
return $string;
}
示例6: action_edit
public function action_edit($account_id = '')
{
// set redirect url
$redirect = $this->getAndSetSubmitRedirection();
// check permission
if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_edit_perm') == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
\Response::redirect($redirect);
}
// if editing guest.
if ($account_id == '0') {
\Response::redirect($redirect);
}
// if no account id, get current user's' account id
if ($account_id == null) {
$cookie = \Model_Accounts::forge()->getAccountCookie('admin');
if (isset($cookie['account_id'])) {
$account_id = $cookie['account_id'];
} else {
unset($cookie);
\Response::redirect($redirect);
}
unset($cookie);
}
// load language
\Lang::load('account');
// load config from db.
$cfg_values = array('allow_avatar', 'avatar_size', 'avatar_allowed_types', 'site_timezone');
$config = \Model_Config::getvalues($cfg_values);
$output['config'] = $config;
// set config data to display in view file.
$output['allow_avatar'] = $config['allow_avatar']['value'];
$output['avatar_size'] = $config['avatar_size']['value'];
$output['avatar_allowed_types'] = $config['avatar_allowed_types']['value'];
unset($cfg_values);
// read flash message for display errors.
$form_status = \Session::get_flash('form_status');
if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
$output['form_status'] = $form_status['form_status'];
$output['form_status_message'] = $form_status['form_status_message'];
}
unset($form_status);
// get timezone list to display.
\Config::load('timezone', 'timezone');
$output['timezone_list'] = \Config::get('timezone.timezone', array());
$output['default_timezone'] = $config['site_timezone']['value'];
// get levels to select
$output['account_levels'] = \Model_AccountLevelGroup::listLevels(array('no_guest' => true));
// get selected user data. -------------------------------------------------------------------------------------
$row = \Model_Accounts::find($account_id);
$output['account_id'] = $account_id;
if ($row == null) {
// not found selected user.
unset($config, $output, $row);
\Response::redirect($redirect);
}
// loop set form field.
foreach ($row as $key => $value) {
$output[$key] = $value;
}
foreach ($row->account_level as $lvl) {
$output['level_group_id'][] = $lvl->level_group_id;
}
// check if editing account that has higher level
if (\Model_Accounts::forge()->canIAddEditAccount($output['level_group_id']) == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('account_you_cannot_edit_account_that_contain_role_higher_than_yours')));
\Response::redirect($redirect);
}
// if form submitted --------------------------------------------------------------------------------------------
if (\Input::method() == 'POST') {
// store data for accounts table
$data['account_id'] = $account_id;
$data['account_username'] = $row->account_username;
//trim(\Input::post('account_username'));//no, do not edit username.
$data['account_old_email'] = $row->account_email;
$data['account_email'] = \Security::strip_tags(trim(\Input::post('account_email')));
$data['account_password'] = trim(\Input::post('account_password'));
$data['account_new_password'] = trim(\Input::post('account_new_password'));
$data['account_display_name'] = \Security::htmlentities(\Input::post('account_display_name'));
$data['account_firstname'] = \Security::htmlentities(trim(\Input::post('account_firstname', null)));
if ($data['account_firstname'] == null) {
$data['account_firstname'] = null;
}
$data['account_middlename'] = \Security::htmlentities(trim(\Input::post('account_middlename', null)));
if ($data['account_middlename'] == null) {
$data['account_middlename'] = null;
}
$data['account_lastname'] = \Security::htmlentities(trim(\Input::post('account_lastname', null)));
if ($data['account_lastname'] == null) {
$data['account_lastname'] = null;
}
$data['account_birthdate'] = \Security::strip_tags(trim(\Input::post('account_birthdate', null)));
if ($data['account_birthdate'] == null) {
$data['account_birthdate'] = null;
}
$data['account_signature'] = \Security::htmlentities(trim(\Input::post('account_signature', null)));
if ($data['account_signature'] == null) {
$data['account_signature'] = null;
}
$data['account_timezone'] = \Security::strip_tags(trim(\Input::post('account_timezone')));
//.........这里部分代码省略.........
示例7:
echo Input::get("id", "");
?>
" />
<ul class="forms">
<li><h4>Name</h4>
<div>
<input placeholder="First name" name="firstname" type="text" required pattern=".{2,20}" title="must be less than 20 chars" value="<?php
echo Security::htmlentities(Input::post("firstname", $user->firstname));
?>
">
<input placeholder="Middle name" name="middlename" type="text" pattern=".{2,20}" title="must be less than 20 chars" value="<?php
echo Security::htmlentities(Input::post("middlename", $user->middlename));
?>
">
<input placeholder="Last name" name="lastname" type="text" required pattern=".{2,20}" title="must be less than 20 chars" value="<?php
echo Security::htmlentities(Input::post("lastname", $user->lastname));
?>
">
</div>
</li>
<li><h4>Email address</h4>
<div>
<?php
if (isset($error)) {
?>
<p class="error"><?php
echo $error;
?>
</p>
<?php
}
示例8: action_edit
public function action_edit($level_group_id = '')
{
// set redirect url
$redirect = $this->getAndSetSubmitRedirection();
// check permission
if (\Model_AccountLevelPermission::checkAdminPermission('accountlv_perm', 'accountlv_edit_perm') == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
\Response::redirect($redirect);
}
// force $level_group_id to be integer
$level_group_id = (int) $level_group_id;
// load language
\Lang::load('account');
// read flash message for display errors.
$form_status = \Session::get_flash('form_status');
if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
$output['form_status'] = $form_status['form_status'];
$output['form_status_message'] = $form_status['form_status_message'];
}
unset($form_status);
// get data to edit
$alg = \Model_AccountLevelGroup::find($level_group_id);
// if not found
if ($alg == null) {
\Response::redirect($redirect);
}
// set output data for form
foreach ($alg as $key => $value) {
$output[$key] = $value;
}
unset($alg, $key, $value);
// if form submitted
if (\Input::method() == 'POST') {
// store data for save in db
$data['level_group_id'] = $level_group_id;
$data['level_name'] = \Security::htmlentities(trim(\Input::post('level_name')));
$data['level_description'] = \Security::htmlentities(trim(\Input::post('level_description')));
// validate form.
$validate = \Validation::forge();
$validate->add('level_name', \Lang::get('accountlv_role'), array(), array('required'));
if (!\Extension\NoCsrf::check()) {
// validate token failed
$output['form_status'] = 'error';
$output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
} elseif (!$validate->run()) {
// validate failed
$output['form_status'] = 'error';
$output['form_status_message'] = $validate->show_errors();
} else {
// save
$result = \Model_AccountLevelGroup::editLevel($data);
if ($result === true) {
if (\Session::get_flash('form_status', null, false) == null) {
\Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('admin_saved')));
}
\Response::redirect($redirect);
} else {
$output['form_status'] = 'error';
$output['form_status_message'] = $result;
}
}
// re-populate form
$output['level_name'] = $data['level_name'];
$output['level_description'] = $data['level_description'];
}
// <head> output ----------------------------------------------------------------------------------------------
$output['page_title'] = $this->generateTitle(\Lang::get('accountlv_role'));
// <head> output ----------------------------------------------------------------------------------------------
// breadcrumb -------------------------------------------------------------------------------------------------
$page_breadcrumb = [];
$page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')];
$page_breadcrumb[1] = ['name' => \Lang::get('accountlv_role'), 'url' => \Uri::create('admin/account-level')];
$page_breadcrumb[2] = ['name' => \Lang::get('accountlv_edit_role'), 'url' => \Uri::main()];
$output['page_breadcrumb'] = $page_breadcrumb;
unset($page_breadcrumb);
// breadcrumb -------------------------------------------------------------------------------------------------
return $this->generatePage('admin/templates/accountlevel/form_v', $output, false);
}
示例9: sendResetPasswordEmail
/**
* send reset password email
*
* @param array $data
* @return mixed
*/
public static function sendResetPasswordEmail(array $data = array())
{
if (!isset($data['account_email'])) {
return false;
}
$query = static::query()->where('account_email', $data['account_email']);
if ($query->count() > 0) {
$row = $query->get_one();
unset($query);
if ($row->account_status == '0') {
return \Lang::get('account_was_disabled') . ' : ' . $row->account_status_text;
}
$cfg_member_confirm_wait_time = \Model_Config::getval('member_confirm_wait_time') * 60;
// check confirm wait time. you need to wait until 'wait time' passed to send reset password request again.
if ($row->account_confirm_code != null && time() - $row->account_confirm_code_since <= $cfg_member_confirm_wait_time) {
return \Lang::get('account_reset_password_please_wait_until', array('wait_til_time' => date('d F Y H:i:s', $row->account_confirm_code_since + \Model_Config::getval('member_confirm_wait_time') * 60)));
}
$account_new_password = \Str::random('alnum', 10);
$account_confirm_code = \Str::random('alnum', 5);
$account_confirm_code_since = time();
$email_content = \Extension\EmailTemplate::readTemplate('reset_password1.html');
$email_content = str_replace("%username%", \Security::htmlentities($row->account_username), $email_content);
$email_content = str_replace("%link_confirm%", \Uri::create('account/resetpw/' . $row->account_id . '/' . $account_confirm_code . '/reset'), $email_content);
$email_content = str_replace("%link_cancel%", \Uri::create('account/resetpw/' . $row->account_id . '/' . $account_confirm_code . '/cancel'), $email_content);
$email_content = str_replace("%confirm_until%", date('d F Y H:i:s', time() + $cfg_member_confirm_wait_time), $email_content);
\Package::load('email');
$config = \Extension\Email::getConfig();
$email = \Email::forge($config);
$email->from(\Model_Config::getval('mail_sender_email'));
$email->to($data['account_email']);
$email->subject(\Lang::get('account_email_reset_password_request'));
$email->html_body($email_content);
$email->alt_body(str_replace("\t", '', strip_tags($email_content)));
if ($email->send() == false) {
unset($account_confirm_code, $account_confirm_code_since, $account_new_password, $cfg_member_confirm_wait_time, $config, $email, $email_content, $query, $row);
return \Lang::get('account_email_could_not_send');
}
unset($cfg_member_confirm_wait_time, $config, $email, $email_content);
// update to db.
//$row->account_new_password = static::instance()->hashPassword($account_new_password);
$row->account_confirm_code = $account_confirm_code;
$row->account_confirm_code_since = $account_confirm_code_since;
$row->save();
unset($account_confirm_code, $account_confirm_code_since, $account_new_password, $row);
return true;
}
// account not found.
return \Lang::get('account_didnot_found_entered_email');
}
示例10:
echo Security::htmlentities($user['charm_why']);
?>
</dd>
<dt>何が得意?</dt>
<dd><?php
echo Security::htmlentities($user['skillfull']);
?>
</dd>
<dt>どうして?</dt>
<dd><?php
echo Security::htmlentities($user['skillfull_why']);
?>
</dd>
<dt>期待していること</dt>
<dd><?php
echo Security::htmlentities($user['expectation']);
?>
</dd>
</dl>
<div class="introducerprofile pull-right"><a href="/user/profile/<?php
echo $user['user_id'];
?>
">
<img src="<?php
echo $user['url'];
?>
"></img>
</a>
<?php
echo $user['name'];
?>
示例11: mention2link_callback
protected static function mention2link_callback($matches)
{
$member_name = $matches[2];
if (!($member = Model_Member::get_one4name($member_name))) {
return $matches[0];
}
$url = Uri::create('member/' . $member->id);
$urlstr = Security::htmlentities($matches[1] . $member_name);
return Html::anchor($url, $urlstr);
}
示例12: foreach
<?php
foreach ($list_accounts['items'] as $row) {
?>
<tr>
<td class="check-column"><?php
echo \Extension\Form::checkbox('id[]', $row->account_id, array($row->account_id == '0' ? 'disabled' : null));
?>
</td>
<td><?php
echo $row->account_id;
?>
</td>
<td><?php
echo \Security::htmlentities($row->account_username);
?>
</td>
<td><?php
echo $row->account_email;
?>
</td>
<td>
<?php
$i = 1;
foreach ($row->account_level as $lvl) {
$lvg = \Model_AccountLevelGroup::find($lvl->level_group_id);
echo $lvg->level_name;
if (end($row->account_level) != $lvl) {
echo ', ';
}
示例13: action_edit
public function action_edit($site_id = '')
{
// set redirect url
$redirect = $this->getAndSetSubmitRedirection();
// check permission
if (\Model_AccountLevelPermission::checkAdminPermission('siteman_perm', 'siteman_edit_perm') == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
\Response::redirect($redirect);
}
// read flash message for display errors.
$form_status = \Session::get_flash('form_status');
if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
$output['form_status'] = $form_status['form_status'];
$output['form_status_message'] = $form_status['form_status_message'];
}
unset($form_status);
// get selected site data
$row = \Model_Sites::find($site_id);
$output['site_id'] = $site_id;
if ($row == null) {
// not found selected site data.
unset($output, $row);
\Response::redirect($redirect);
}
// loop set form field.
foreach ($row as $key => $value) {
$output[$key] = $value;
}
// if form submitted
if (\Input::method() == 'POST') {
// store data for save
$data['site_id'] = $site_id;
$data['site_name'] = \Security::htmlentities(trim(\Input::post('site_name')));
$data['site_domain'] = str_replace(array('http://', '/'), '', mb_strtolower(\Security::strip_tags(trim(\Input::post('site_domain')))));
$data['site_status'] = (int) trim(\Input::post('site_status'));
$validate = \Validation::forge();
$validate->add_callable(new \Extension\FsValidate());
$validate->add('site_name', \Lang::get('siteman_site_name'), array(), array('required'));
$validate->add('site_domain', \Lang::get('siteman_site_domain'), array(), array('required'));
if (!\Extension\NoCsrf::check()) {
// validate token failed
$output['form_status'] = 'error';
$output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
} elseif (!$validate->run()) {
// validate failed
$output['form_status'] = 'error';
$output['form_status_message'] = $validate->show_errors();
} else {
// save
$result = \Model_Sites::editSite($data);
if ($result === true) {
if (\Session::get_flash('form_status', null, false) == null) {
\Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('admin_saved')));
}
\Response::redirect($redirect);
} else {
$output['form_status'] = 'error';
$output['form_status_message'] = $result;
}
}
// re-populate form
$output['site_name'] = \Input::post('site_name');
$output['site_domain'] = \Input::post('site_domain');
$output['site_status'] = \Input::post('site_status');
}
// <head> output ----------------------------------------------------------------------------------------------
$output['page_title'] = $this->generateTitle(\Lang::get('siteman_multisite_manager'));
// <head> output ----------------------------------------------------------------------------------------------
// breadcrumb -------------------------------------------------------------------------------------------------
$page_breadcrumb = [];
$page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')];
$page_breadcrumb[1] = ['name' => \Lang::get('siteman_multisite_manager'), 'url' => \Uri::create('admin/siteman')];
$page_breadcrumb[2] = ['name' => \Lang::get('siteman_edit'), 'url' => \Uri::main()];
$output['page_breadcrumb'] = $page_breadcrumb;
unset($page_breadcrumb);
// breadcrumb -------------------------------------------------------------------------------------------------
return $this->generatePage('admin/templates/siteman/form_v', $output, false);
}
示例14: action_edit
public function action_edit($post_id = '')
{
// check permission
if (\Model_AccountLevelPermission::checkAdminPermission('blog_perm', 'blog_write_perm') == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
\Response::redirect(\Uri::create('blog/admin'));
}
// read flash message for display errors.
$form_status = \Session::get_flash('form_status');
if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
$output['form_status'] = $form_status['form_status'];
$output['form_status_message'] = $form_status['form_status_message'];
}
unset($form_status);
// get current post data for form
$row = \Blog\Model_Blog::find($post_id);
if ($row == null) {
\Response::redirect(\Uri::create('blog/admin'));
}
// loop set form field.
foreach ($row as $key => $value) {
$output[$key] = $value;
}
// if form submitted --------------------------------------------------------------------------------------------
if (\Input::method() == 'POST') {
// store data for save
$data['post_id'] = $post_id;
$data['post_name'] = \Security::htmlentities(trim(\Input::post('post_name')));
$data['post_body'] = trim(\Input::post('post_body'));
// validate form.
$validate = \Validation::forge();
$validate->add('post_name', \Lang::get('blog_post_name'), array(), array('required'));
$validate->add('post_body', \Lang::get('blog_post_content'), array(), array('required'));
if (!\Extension\NoCsrf::check()) {
// validate token failed
$output['form_status'] = 'error';
$output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
} elseif (!$validate->run()) {
// validate failed
$output['form_status'] = 'error';
$output['form_status_message'] = $validate->show_errors();
} else {
$result = \Blog\Model_Blog::editPost($data);
if ($result === true) {
if (\Session::get_flash('form_status', null, false) == null) {
\Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('admin_saved')));
}
\Response::redirect(\Uri::create('blog/admin'));
} else {
$output['form_status'] = 'error';
$output['form_status_message'] = $result;
}
}
// re-populate form
$output['post_name'] = $data['post_name'];
$output['post_body'] = $data['post_body'];
}
unset($row);
// <head> output ----------------------------------------------------------------------------------------------
$output['page_title'] = $this->generateTitle(\Lang::get('blog'));
// <head> output ----------------------------------------------------------------------------------------------
return $this->generatePage('admin/blog_form_v', $output, false);
}
示例15: view
public function view()
{
/* @var $table \Doctrine\DBAL\Schema\Table */
$table = $this->__table;
$this->table_name = $table->getName();
$this->columns = array();
$indexes = $table->getIndexes();
$foreign_keys = $table->getForeignKeys();
$functions = \Config::get('dbdocs.functions');
foreach ($table->getColumns() as $column) {
/* @var $column \Doctrine\DBAL\Schema\Column */
$comment = \Security::htmlentities($column->getComment());
if (is_callable($functions['mod_comment'])) {
$comment = $functions['mod_comment']($comment, $column->getName(), $table->getName());
}
$this->columns[$column->getName()] = array('type' => $column->getType()->getName(), 'length' => $column->getLength(), 'null' => !$column->getNotnull(), 'default' => $column->getDefault(), 'comment' => $comment, 'extras' => array());
foreach ($indexes as $index) {
if (in_array($column->getName(), $index->getColumns())) {
if ($index->isPrimary()) {
$this->columns[$column->getName()]['extras'][] = 'PK';
} else {
if ($index->isUnique()) {
$this->columns[$column->getName()]['extras'][] = 'UI';
} else {
if ($index->isSimpleIndex()) {
$this->columns[$column->getName()]['extras'][] = 'I';
}
}
}
}
}
$column->getAutoincrement() and $this->columns[$column->getName()]['extras'][] = 'AI';
$column->getUnsigned() and $this->columns[$column->getName()]['extras'][] = 'UN';
foreach ($foreign_keys as $foreign_key) {
/* @var $foreign_key \Doctrine\DBAL\Schema\ForeignKeyConstraint */
if (in_array($column->getName(), $foreign_key->getColumns())) {
$flip = array_flip($this->columns[$column->getName()]['extras']);
if (isset($flip['I'])) {
unset($flip['I']);
$this->columns[$column->getName()]['extras'] = array_flip($flip);
}
$this->columns[$column->getName()]['extras'][] = 'FK';
$this->columns[$column->getName()]['foreign_key']['table_name'] = $foreign_key->getForeignTableName();
$foreign_key_columns = $foreign_key->getForeignColumns();
$this->columns[$column->getName()]['foreign_key']['column_name'] = $foreign_key_columns[0];
}
}
if (!isset($this->columns[$column->getName()]['foreign_key'])) {
if (is_callable($functions['mod_foreign_key'])) {
$this->columns[$column->getName()]['foreign_key'] = $functions['mod_foreign_key']($column->getName(), $table->getName());
}
}
}
/**
* get real information of columns
*/
$dd = Dbdocs::instance('default');
$platform = $dd->conn->getDatabasePlatform()->getName();
switch ($platform) {
case 'mysql':
$rows = $dd->conn->executeQuery('
select
*
from
information_schema.columns
where
table_schema = :table_schema
and
table_name = :table_name
order by
ordinal_position', array('table_name' => $this->table_name, 'table_schema' => $dd->conn->getDatabase()))->fetchAll();
foreach ($rows as $row) {
$real_columns[$row['COLUMN_NAME']] = array('type' => $row['DATA_TYPE'], 'length' => $row['CHARACTER_MAXIMUM_LENGTH'], 'default' => $row['COLUMN_DEFAULT']);
}
break;
default:
$real_columns = array();
break;
}
$this->set('columns', \Arr::merge($this->columns, $real_columns), false);
$this->indexes = static::merge_indexes_and_foreign_keys($indexes, $foreign_keys, $table);
}