本文整理汇总了PHP中CHtml::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::encode方法的具体用法?PHP CHtml::encode怎么用?PHP CHtml::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$voting = null;
if (is_numeric(HU::post('id_voting'))) {
$voting = Voting::model()->onlyActive()->with('answer')->findByPk(HU::post('id_voting'));
}
if ($voting == null) {
//echo CHtml::encode($this->controller->widget('vote.widgets.VoteWidget', null, true));
return;
}
if (Yii::app()->vote->check($voting->id_voting)) {
$answers = $_POST['VotingAnswer']['name'];
$cr = new CDbCriteria();
$cr->addColumnCondition(array('id_voting' => $voting->id_voting));
if (is_array($answers)) {
$cr->addInCondition('id_voting_answer', $answers);
} else {
if (is_numeric($answers)) {
$cr->addColumnCondition(array('id_voting_answer' => $answers));
}
}
VotingAnswer::model()->updateCounters(array('count' => 1), $cr);
VisitSite::saveCurrentVisit(Voting::ID_OBJECT, $voting->id_voting);
Yii::app()->user->setState('vote_' . $voting->id_voting, time());
// перегружаем голосовалку, чтоб обновились показатели счетчиков
$voting = Voting::model()->onlyActive()->with('answer')->findByPk($voting->id_voting);
}
$voteCount = $voting->getSumVote();
echo CHtml::encode($this->controller->renderPartial("vote.widgets.views.statistic", array('voting' => $voting, 'voteCount' => $voteCount)), null, true);
}
示例2: actionLogin
/**
* 会员登录
*/
public function actionLogin()
{
$model = new Admin('login');
if (XUtils::method() == 'POST') {
$model->attributes = $_POST['Admin'];
if ($model->validate()) {
$data = $model->find('username=:username', array('username' => $model->username));
if ($data === null) {
$model->addError('username', '用户不存在');
AdminLogger::_create(array('catalog' => 'login', 'intro' => '登录失败,用户不存在:' . CHtml::encode($model->username), 'user_id' => 0));
} elseif (!$model->validatePassword($data->password)) {
$model->addError('password', '密码不正确');
AdminLogger::_create(array('catalog' => 'login', 'intro' => '登录失败,密码不正确:' . CHtml::encode($model->username) . ',使用密码:' . CHtml::encode($model->password), 'user_id' => 0));
} elseif ($data->group_id == 2) {
$model->addError('username', '用户被锁定,请联系网站管理');
} else {
parent::_stateWrite(array('userId' => $data->id, 'userName' => $data->username, 'groupId' => $data->group_id, 'super' => $data->group_id == 1 ? 1 : 0), array('prefix' => '_admini'));
$data->last_login_ip = XUtils::getClientIP();
$data->last_login_time = time();
$data->login_count = $data->login_count + 1;
$data->save();
AdminLogger::_create(array('catalog' => 'login', 'intro' => '用户登录成功:' . CHtml::encode($model->username)));
$this->redirect(array('default/index'));
}
}
}
$this->render('login', array('model' => $model));
}
示例3: run
/**
* Renders the content of the widget.
* @throws CException
*/
public function run()
{
// Hide empty breadcrumbs.
if (empty($this->links)) {
return;
}
$links = array();
if (!isset($this->homeLink)) {
$content = CHtml::link(Yii::t('zii', 'Inicio'), Yii::app()->homeUrl);
$links[] = $this->renderItem($content);
} else {
if ($this->homeLink !== false) {
$links[] = $this->renderItem($this->homeLink);
}
}
foreach ($this->links as $label => $url) {
if (is_string($label) || is_array($url)) {
$content = CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url);
$links[] = $this->renderItem($content);
} else {
$links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
}
}
echo CHtml::tag('ul', $this->htmlOptions, implode('', $links));
}
示例4: actionAjaxAdd
public function actionAjaxAdd()
{
if (Yii::app()->request->isAjaxRequest && Yii::app()->user->checkAccess('blockip_admin')) {
$postValue = CHtml::encode(strip_tags(Yii::app()->request->getParam('value')));
$pk = CHtml::encode(strip_tags(Yii::app()->request->getParam('pk')));
if ($postValue) {
$blockIpModel = BlockIp::model()->find('ip = :ip', array(':ip' => $postValue));
if ($blockIpModel) {
# IP уже есть
$msg = 'already_exists';
} else {
$blockIpModel = new BlockIp();
$blockIpModel->ip = $postValue;
$blockIpModel->ip_long = ip2long($postValue);
$blockIpModel->date_created = new CDbExpression('NOW()');
if ($blockIpModel->save()) {
$msg = 'ok';
} else {
$msg = 'save_error';
}
}
} else {
$msg = 'no_value';
}
echo CJSON::encode(array('msg' => $msg, 'value' => $postValue, 'pk' => $pk));
Yii::app()->end();
}
}
示例5: run
public function run()
{
if (empty($this->links)) {
return;
}
if (isset($this->htmlOptions['class'])) {
$this->htmlOptions['class'] .= ' breadcrumb';
} else {
$this->htmlOptions['class'] = 'breadcrumb';
}
echo CHtml::openTag($this->tagName, $this->htmlOptions) . "\n";
$links = array();
if ($this->homeLink === null) {
$links[] = CHtml::link(Yii::t('zii', 'Home'), Yii::app()->homeUrl);
} else {
if ($this->homeLink !== false) {
$links[] = $this->homeLink;
}
}
foreach ($this->links as $label => $url) {
if (is_string($label) || is_array($url)) {
$links[] = CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url);
} else {
$links[] = '<span>' . ($this->encodeLabel ? CHtml::encode($url) : $url) . '</span>';
}
}
$separator = CHtml::tag('span', array('class' => 'divider'), $this->separator) . CHtml::closeTag('li') . ' ' . CHtml::openTag('li');
echo CHtml::openTag('li') . implode($separator, $links) . CHtml::closeTag('li');
echo CHtml::closeTag($this->tagName);
}
示例6: renderContent
protected function renderContent()
{
if (isset($this->block) && $this->block != null) {
//Set Params from Block Params
$params = unserialize($this->block->params);
$this->setParams($params);
$post_id = (int) $_GET['id'];
if ($post_id) {
$post = Object::model()->findByPk($post_id);
if ($post) {
Yii::app()->controller->pageTitle = CHtml::encode($post->object_name);
Yii::app()->controller->description = CHtml::encode($post->object_description);
Yii::app()->controller->keywords = CHtml::encode($post->object_keywords);
Yii::app()->controller->change_title = true;
$this->render(BlockRenderWidget::setRenderOutput($this), array('post' => $post));
} else {
throw new CHttpException('404', t('Page not found'));
}
} else {
throw new CHttpException('404', t('Page not found'));
}
} else {
echo '';
}
}
示例7: onNewComment
public static function onNewComment(CommentEvent $event)
{
$comment = $event->getComment();
$module = $event->getModule();
$parent = $comment->getParent();
//ответ на комментарий
if ($comment->hasParent()) {
if (null !== $parent && $parent->user_id) {
$notify = NotifySettings::model()->getForUser($parent->user_id);
if (null !== $notify && $notify->isNeedSendForCommentAnswer()) {
Yii::app()->mail->send($module->email, $parent->email, Yii::t('NotifyModule.notify', 'Reply to your comment on the website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-reply-notify-email', ['model' => $comment], true));
}
}
}
//нотификация автору поста
if ('Post' === $comment->model) {
$post = Post::model()->cache(Yii::app()->getModule('yupe')->coreCacheTime)->with(['createUser'])->get((int) $comment->model_id);
if (null !== $post) {
//пропускаем автора поста + если отвечают на комментарий автора поста - он уже получил уведомление выше
if ($comment->user_id != $post->create_user_id) {
$notify = NotifySettings::model()->getForUser($post->create_user_id);
if (null != $notify && $notify->isNeedSendForNewPostComment()) {
Yii::app()->mail->send($module->email, $post->createUser->email, Yii::t('NotifyModule.notify', 'New comment to your post on website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-new-notify-email', ['model' => $comment], true));
}
}
}
}
}
示例8: actionAdd
public function actionAdd($isFancy = 0)
{
$model = new Reviews();
if (isset($_POST[$this->modelName])) {
$model->attributes = $_POST[$this->modelName];
if ($model->validate()) {
if ($model->save(false)) {
$model->name = CHtml::encode($model->name);
$model->body = CHtml::encode($model->body);
$notifier = new Notifier();
$notifier->raiseEvent('onNewReview', $model);
if (Yii::app()->user->getState('isAdmin')) {
Yii::app()->user->setFlash('success', tt('success_send_not_moderation'));
} else {
Yii::app()->user->setFlash('success', tt('success_send'));
}
$this->redirect(array('index'));
}
$model->unsetAttributes(array('name', 'body', 'verifyCode'));
} else {
Yii::app()->user->setFlash('error', tt('failed_send'));
}
$model->unsetAttributes(array('verifyCode'));
}
if ($isFancy) {
$this->excludeJs();
$this->renderPartial('add', array('model' => $model), false, true);
} else {
$this->render('add', array('model' => $model));
}
}
示例9: etiquetaExtranjero
/**
* @return html nombre de partida compuesto con el nombre
*/
public function etiquetaExtranjero()
{
//echo count($this->id);
//die;
$extranjero = ProveedoresExtranjeros::model()->findByAttributes(array('proveedor_id' => $this->id));
return CHtml::encode($this->rif . ' - ' . $this->razon_social . ' - ' . $extranjero->num_identificacion . ' - ' . $extranjero->pais->nombre);
}
示例10: run
public function run()
{
if (empty($this->links)) {
return;
}
$this->activeLinkTemplate = '<a href="{url}" title="{title}" rel="v:url" property="v:title">{label}</a>';
echo CHtml::openTag($this->tagName, $this->htmlOptions) . "\n";
$links = array();
if ($this->homeLink === null) {
$links[] = CHtml::link(Yii::t('zii', 'Home'), Yii::app()->homeUrl);
} elseif ($this->homeLink !== false) {
$links[] = $this->homeLink;
}
foreach ($this->links as $label => $url) {
if (is_string($label) || is_array($url)) {
$links[] = strtr($this->activeLinkTemplate, array('{url}' => CHtml::normalizeUrl($url), '{label}' => $this->encodeLabel ? CHtml::encode($label) : $label, '{title}' => $this->encodeLabel ? CHtml::encode($label) : $label));
} else {
$links[] = str_replace('{label}', $this->encodeLabel ? CHtml::encode($url) : $url, $this->inactiveLinkTemplate);
}
}
echo "<div xmlns:v='http://rdf.data-vocabulary.org/#'>";
$i = 0;
foreach ($links as $link) {
if ($i > 0) {
echo ' <i class="icon icon_mt"></i> ';
}
echo '<span typeof="v:Breadcrumb">' . $link . '</span>';
$i++;
}
echo "</div>";
//echo implode($this->separator,$links);
echo CHtml::closeTag($this->tagName);
}
示例11: actionAdd
public function actionAdd($isFancy = 0)
{
$model = new Vacancy();
if (isset($_POST[$this->modelName]) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) {
$model->attributes = $_POST[$this->modelName];
if ($model->validate()) {
$model->user_ip = Yii::app()->controller->currentUserIp;
$model->user_ip_ip2_long = Yii::app()->controller->currentUserIpLong;
if ($model->save(false)) {
$model->name = CHtml::encode($model->name);
$model->body = CHtml::encode($model->body);
$notifier = new Notifier();
$notifier->raiseEvent('onNewReview', $model);
if (Yii::app()->user->checkAccess('vacancy_admin')) {
Yii::app()->user->setFlash('success', tt('success_send_not_moderation'));
} else {
Yii::app()->user->setFlash('success', tt('success_send'));
}
$this->redirect(array('index'));
}
$model->unsetAttributes(array('name', 'body', 'verifyCode'));
} else {
Yii::app()->user->setFlash('error', tt('failed_send'));
}
$model->unsetAttributes(array('verifyCode'));
}
if ($isFancy) {
$this->excludeJs();
$this->renderPartial('add', array('model' => $model), false, true);
} else {
$this->render('add', array('model' => $model));
}
}
示例12: renderHeaderCell
/**
* Renders the header cell.
*/
public function renderHeaderCell()
{
if ($this->grid->json) {
$header = array('id' => $this->id);
$content = array();
if ($this->grid->enableSorting && $this->sortable && $this->name !== null) {
$sort = $this->grid->dataProvider->getSort();
$label = isset($this->header) ? $this->header : $sort->resolveLabel($this->name);
if ($sort->resolveAttribute($this->name) !== false) {
$label .= '<span class="caret"></span>';
}
$content['content'] = $sort->link($this->name, $label, array('class' => 'sort-link'));
} else {
if ($this->name !== null && $this->header === null) {
if ($this->grid->dataProvider instanceof CActiveDataProvider) {
$content['content'] = CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
} else {
$content['content'] = CHtml::encode($this->name);
}
} else {
$content['content'] = trim($this->header) !== '' ? $this->header : $this->grid->blankDisplay;
}
}
return CMap::mergeArray($header, $content);
}
parent::renderHeaderCell();
}
示例13: actionJson
/**
* JSON Search for Users
*
* Returns an array of users with fields:
* - guid
* - displayName
* - image
* - profile link
*/
public function actionJson()
{
$maxResults = 10;
$results = array();
$keyword = Yii::app()->request->getParam('keyword');
$keyword = Yii::app()->input->stripClean($keyword);
// Build Search Condition
$criteria = new CDbCriteria();
$criteria->limit = $maxResults;
$criteria->condition = 1;
$criteria->params = array();
$i = 0;
foreach (explode(" ", $keyword) as $part) {
$i++;
$criteria->condition .= " AND (t.email LIKE :match{$i} OR " . "t.username LIKE :match{$i} OR " . "userProfile.firstname LIKE :match{$i} OR " . "userProfile.lastname LIKE :match{$i} OR " . "userProfile.title LIKE :match{$i})";
$criteria->params[':match' . $i] = "%" . $part . "%";
}
$users = User::model()->with('userProfile')->findAll($criteria);
foreach ($users as $user) {
if ($user != null) {
$userInfo = array();
$userInfo['guid'] = $user->guid;
$userInfo['displayName'] = CHtml::encode($user->displayName);
$userInfo['image'] = $user->getProfileImage()->getUrl();
$userInfo['link'] = $user->getUrl();
$results[] = $userInfo;
}
}
print CJSON::encode($results);
Yii::app()->end();
}
示例14: actionView
public function actionView()
{
$topic = $this->getTopic();
$file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $this->getLanguage() . DIRECTORY_SEPARATOR . $topic . '.txt';
if (!is_file($file)) {
$file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $topic . '.txt';
}
if (!strcasecmp($topic, 'toc') || !is_file($file)) {
throw new CHttpException(404, 'The requested page does not exist.');
}
$content = file_get_contents($file);
$markdown = new MarkdownParser();
$markdown->purifierOptions['Attr.EnableID'] = true;
$content = $markdown->safeTransform($content);
$highlightCss = Yii::app()->assetManager->publish($markdown->getDefaultCssFile());
Yii::app()->clientScript->registerCssFile($highlightCss);
$imageUrl = Yii::app()->baseUrl . '/images/guide';
$content = preg_replace('/<p>\\s*<img(.*?)src="(.*?)"\\s+alt="(.*?)"\\s*\\/>\\s*<\\/p>/', '<div class="image"><p>\\3</p><img\\1src="' . $imageUrl . '/\\2" alt="\\3" /></div>', $content);
$content = preg_replace_callback('/href="\\/guide\\/(.*?)\\/?"/', array($this, 'replaceGuideLink'), $content);
$content = preg_replace('/href="(\\/api\\/.*?)"/', 'href="http://sourcebans.net$1"', $content);
$content = preg_replace_callback('/<h2([^>]*)>(.*?)<\\/h2>/', array($this, 'replaceSection'), $content);
$content = preg_replace_callback('/<h1([^>]*)>(.*?)<\\/h1>/', array($this, 'replaceTitle'), $content, 1);
$this->pageTitle = 'User Guide « SourceBans';
if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
$this->pageTitle = CHtml::encode($matches[1]) . ' « ' . $this->pageTitle;
}
$this->render('view', array('content' => $content));
}
示例15: actionAvatar
public function actionAvatar($user, $hash)
{
$cache_id = "Product:[avatarForUser] " . CHtml::encode($user);
$cache_duration = 3600;
$avatarBinary = Yii::app()->cache->get($cache_id);
if (!$avatarBinary) {
$result = Yii::app()->curl->post("https://kle-en-main.com/CloudServices/index.php/BoukemAPI/product/avatar", array('user_id' => $user, 'hash' => $hash, 'store_id' => Yii::app()->params['outbound_api_user'], 'store_key' => Yii::app()->params['outbound_api_secret']));
$json_dict = json_decode($result);
if (!$json_dict) {
throw new CHttpException(404, Yii::t('app', 'La page demandée n\'existe pas.'));
}
$avatarBinary = $json_dict->avatar_medium;
Yii::app()->cache->set($cache_id, $avatarBinary, $cache_duration);
}
$raw_data = base64_decode($avatarBinary);
header('Content-Type: image/jpeg');
echo $raw_data;
foreach (Yii::app()->log->routes as $route) {
if ($route instanceof CWebLogRoute) {
$route->enabled = false;
// disable any weblogroutes
}
}
Yii::app()->end();
}