WebSite X5Help Center

 
Lucio Flavio
Lucio Flavio
User

Inserir o nome de usuário logado automaticamente no campo "Nome" no Comentário  pt

Author: Lucio Flavio
Visited 2308, Followers 1, Shared 0  

Como inserir o nome de usuário logado automaticamente no campo "Nome" no formulário de comentário no blog ?

achei esses códigos no _x5engine.php_ mas não consego fazer funcionar:

/**
* Get an array of data about the logged user
*
* @method whoIsLogged
*
* @return {mixed} An array containing the data of the current logged user or false if no user is logged.
*/
function whoIsLogged()
{
global $imSettings;
if (isset($_SESSION[$this->session_uname]) && $_SESSION[$this->session_uname] != "" && isset($_SESSION[$this->session_uname])) {
$uname = $this->_decode($_SESSION[$this->session_uname], $this->salt);
return array(
"username" => $uname,
"uid" => $this->_decode($_SESSION[$this->session_uid], $this->salt),
"realname" => $this->_decode($_SESSION[$this->session_real_name], $this->salt),
"groups" => $_SESSION[$this->session_gids]
);
}
return false;
}

.

.

.

/*
|-------------------------------------------
| Show the form
|-------------------------------------------
*/

if (isset($_GET[$this->id . 'success'])) {
echo "<div class=\"alert alert-green\">" . l10n('blog_send_confirmation') . "</div>";
} else if (isset($_GET[$this->id . 'error'])) {
echo "<div class=\"alert alert-red\">" . l10n('blog_send_error') . "</div>";
}

echo "<div class=\"topic-form\">
<form id=\"" . $id ."\" action=\"" . $this->posturl . "\" method=\"post\" onsubmit=\"return x5engine.imForm.validate(this, {type: 'tip', showAll: true})\">
<input type=\"hidden\" name=\"post_id\" value=\"" . $this->id . "\"/>
<div class=\"topic-form-row\">
<label for=\"" . $id . "-name\" style=\"float: left; width: 100px;\">" . l10n('blog_name') . "*</label> <input type=\"text\" id=\"" . $id . "-name\" name=\"name\" class=\"imfield mandatory\" value=\" AQUI TEM QUE ENTRAR O "realname" DO USUÁRIO \" />
</div>
<div class=\"topic-form-row\">
<label for=\"" . $id . "-email\" style=\"float: left; width: 100px;\">" . l10n('blog_email') . "*</label> <input type=\"text\" id=\"" . $id . "-email\" name=\"email\" class=\"imfield mandatory valEmail\"/>
</div>
<div class=\"topic-form-row\">
<label for=\"" . $id . "-url\" style=\"float: left; width: 100px;\">" . l10n('blog_website') . "</label> <input type=\"text\" id=\"" . $id . "-url\" name=\"url\" />
</div>";

Posted on the
4 ANSWERS - 1 CORRECT
Incomedia
Riccardo P.
Incomedia

Hello Lucio,

automatically with WebSite X5 is not possible, you can open a new post in the Idea section sothatis evaluated.

Wait more information about your question by other use of this community.

Thank you.

***** Google Translation:

OláLucio,

automaticamente com oWebSiteX5não é possível, você pode abriruma nova mensagemna seçãoIdeapara queseja avaliado.

Aguardemais informações sobrea sua perguntaporoutra utilizaçãodesta comunidade.

Obrigado.

Read more
Posted on the from Riccardo P.
Lucio Flavio
Lucio Flavio
User
Author

Eu estou tentando fazer com esse código na pagina blog/index.php :

<?php
$db = getDbData($imSettings['access']['dbid']);
$pa = new ImPrivateArea();

$pa->setDbData($db['host'], $db['user'], $db['password'], $db['database'], $imSettings['access']['dbtable']);
foreach ($pa->myfunction() as $user);
?>
.
.
.
.

<script type="text/javascript">
$(function() {

$("input[name='name']").val("<?php echo "{$user['realname']}" ?>");
});

</script>

e adicionei esse código em res/x5engine.php:

function myfunction($ids = array())

{

$res = $this->db->query("SELECT * FROM `" . $this->db_table . "`" . (count($ids) ? " WHERE `id` IN (" . implode(",", $ids) . ")" : ""));

$users = array();
if (is_array($res)) {
foreach ($res as $user) {
$users[] = array(
"id" => $user['id'],
"ts" => $user['ts'],
"ip" => $user['ip'],
"username" => $user['username'],
"password" => $user['password'],
"realname" => $user['realname'],
"email" => $user['email'],
"key" => $user['key'],
"validated" => $user['validated']
);
}
}
return $users;
}

porém está coletando dados de outros usuários,

como eu faço para coletar os dados do usuário logado?

essa função do x5engine.php tem envolvimento com isso?

/**
* Get an array of data about the logged user
*
* @method whoIsLogged
*
* @return {mixed} An array containing the data of the current logged user or false if no user is logged.
*/
function whoIsLogged()
{
global $imSettings;
if (isset($_SESSION[$this->session_uname]) && $_SESSION[$this->session_uname] != "" && isset($_SESSION[$this->session_uname])) {
$uname = $this->_decode($_SESSION[$this->session_uname], $this->salt);
return array(
"username" => $uname,
"uid" => $this->_decode($_SESSION[$this->session_uid], $this->salt),
"realname" => $this->_decode($_SESSION[$this->session_real_name], $this->salt),
"groups" => $_SESSION[$this->session_gids]
);
}
return false;
}

Basicamente eu preciso coletar dados do usuário logado e o jquery vai coloca-lo no lugar do nome no formulário,

Por favor me ajudem a conseguir coletar os dados do usuário logado ficarei muito agradecido se conseguirem me ajudar.

Read more
Posted on the from Lucio Flavio
Incomedia
Riccardo P.
Incomedia

Hello Lucio,

i am sorry but i can't help you.

Please wait more information about this by another users of this community.

Thank you.

***** Google Translation:

OláLucio,

Lamento, masnão possoajudá-lo.

Por favor, aguardemais informações sobreisso pormaisusuáriosdesta comunidade.

Obrigado.

Read more
Posted on the from Riccardo P.
Lucio Flavio
Lucio Flavio
User
Author

Hello Lucio,

I'm not sure that I understand you correctly, but if you seek the correct syntax for the code you quoted then it would be as follows:

<?php echo $_SESSION['realname']; ?>

However, that won't work on its own.  If you want to capture the logged in user within WebSite X5 then you need some extra steps:

Be sure to start the session on the page in question (code in header):

i.e. <?php session_start(); ?>

Followed by this code:

<?php

$pa = new imPrivateArea();

$user = $pa->who_is_logged();

?>

You can then return the name of the logged in user by way of the following code:

<?php echo $user['realname']; ?>

Hope this is what you are looking for...

Kind regards,

Paul M 

Moderador

Posted on the 07/06/2015 19:46:40

Read more
Posted on the from Lucio Flavio