Posts: 538
Threads: 12
Joined: May 2013
Hi jeckyl,
I am not sure if I have understood you properly, with "position", do you mean the field position or position of what?
Look, I have created a user "bigin" with following fields:
My PHP code in template:
PHP Code: $userid = 1; $imanager = imanager(); $user = $imanager->getItem('slug=Users', $userid);
echo '<h2>User data</h2>'; echo '<table>'; foreach ($user->fields as $data) { if(isset($data->value)) { echo ' <tr> <td><strong>'.$data->label.': </strong></td> <td>'.$data->value.'</td> </tr> '; } } echo '</table>';
And here's my output, field position seems correct?:
Posts: 35
Threads: 2
Joined: Aug 2009
Ok, it's working for you but for me i have this result.
Posts: 538
Threads: 12
Joined: May 2013
strange, have you tried my snippet, same result?
look at the "/data/imanager/fields/*.im.fields.xml" file, is there the order correct?
Show me your original code snippet for output pls
Posts: 35
Threads: 2
Joined: Aug 2009
(2017-02-07, 05:16:52)Bigin Wrote: strange, have you tried my snippet, same result?
look at the "/data/imanager/fields/*.im.fields.xml" file, is there the order correct?
Show me your original code snippet for output pls
same result with your code.
actually fields are displayed in ID's order and not Position's order.
Code: <?php
// this lines should always be above the rest.
if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
if(!isset($_SESSION)){session_start();}
$userid = (!empty($_SESSION['userid']) ? (int) $_SESSION['userid'] : false);
if (!$userid) {
header('Location: http://xxxxxxxx.org/login/');
exit;
}
$imanager = imanager();
$user = $imanager->getItem('slug=Users', $userid );
?>
Code: <table class="invoices">
<?php
foreach ($user->fields as $data) {
if (isset($data->value)) {
echo '
<tr>
<th>' . $data->label . '</th>
<td>' . $data->value . '</td>
</tr>
';
}
}
?>
</table>
Posts: 538
Threads: 12
Joined: May 2013
2017-02-07, 08:49:33
(This post was last modified: 2017-02-07, 08:57:12 by Bigin.)
Ok, there you have at least two options.
You can just reorder the fields each time you output the user data (simple solution but maybe a bit odd):
PHP Code: $userid = 1; $imanager = imanager(); $user = $imanager->getItem('slug=Users', $userid); $fieldMapper = new FieldMapper(); $fields = $fieldMapper->filterFields('position', 'ASC', (array) $user->fields); foreach($fields as $field) { ...
My recommendation is, to reorder the fields according to their position and save them in this order. So you'll have to loop through users and re-save the fields id's, but only once. Then you must delete this snippet (Perform a backup of the "/data/imanager" folder before execute the code!):
PHP Code: // Reorder item fields by position $imanager = imanager(); $category = $imanager->getCategory('slug=Users'); $users = $imanager->getItems($category->id); $fieldMapper = new FieldMapper(); foreach($users as $user) { $fields = $fieldMapper->filterFields('position', 'ASC', (array) $user->fields); foreach($fields as $field) { $field->id = $field->position; $field->save(); $user->fields->{$field->name}->id = $field->position; } $user->save(); }
Now you can use your snippet as before:
PHP Code: // Dispalay user fields $userid = 1; $imanager = imanager(); $user = $imanager->getItem('slug=Users', $userid); echo '<table>'; foreach ($user->fields as $data) { if(isset($data->value)) { echo ' <tr> <td><strong>'.$data->label.': </strong></td> <td>'.$data->value.'</td> </tr> '; } } echo '</table>';
Posts: 35
Threads: 2
Joined: Aug 2009
Posts: 14
Threads: 0
Joined: Sep 2010
Hello,
I'm testing the frontainer plugin but I can't get it running.
I use GS 3.3.13 fresh install with the only installed imanager and frontainer plugins.
I have configured the required pages and items, but I can't enable the login feature.
Where am I wrong?
You can try url https://intento.ns0.it
Thank you
Posts: 538
Threads: 12
Joined: May 2013
Hi nicco,
I can't access the pages you have created, not a single one seems to be working well, look:
https://intento.ns0.it/login/
https://intento.ns0.it/recovery/
https://intento.ns0.it/signup/
I get 500 (Internal Server Error) there. You should disable all your plugins and fix the 500 error first, before you starting using frontainer.
Posts: 14
Threads: 0
Joined: Sep 2010
(2017-05-12, 20:38:15)Bigin Wrote: Hi nicco,
I can't access the pages you have created, not a single one seems to be working well, look:
https://intento.ns0.it/login/
https://intento.ns0.it/recovery/
https://intento.ns0.it/signup/
I get 500 (Internal Server Error) there. You should disable all your plugins and fix the 500 error first, before you starting using frontainer.
Hi Bigin,
thanks for your quick interest!
I have attached what I get with url https://intento.ns0.it.
When I disable all plugins pages are completely white. I think because I modified the template.php as you indicated in the forum.
Thank you so much, if you want, I can PM you admin credentials.
Posts: 538
Threads: 12
Joined: May 2013
2017-05-13, 00:58:52
(This post was last modified: 2017-05-13, 01:11:10 by Bigin.)
hmm, I believe that, what I have described in forum causes confusion, I'll change that description now..
First of, if you are working with PHP, in order to detect errors resulting from the code: turn on debug mode in gsconfig.php and enable full error reporting (including notices and messages), if necessary. then, however, you'll be able to recognize and eliminate such errors quickly and successfully.
Try the following, change the code in your template to this:
Code: if(!defined('IN_GS')) die();
if(!isset($_SESSION)){session_start();}
$fnavi = array(
'login' => null,
'signup' => null,
'accounts' => null,
'logout' => null,
'recovery' => null
);
$fcontent = '';
if(function_exists('frontainer_get_content')) {
$fcontent = frontainer_get_content();
$fnavi['login'] = htmlspecialchars(get_section_url(LOGIN_SLUG));
$fnavi['signup'] = htmlspecialchars(get_section_url(SIGNUP_SLUG));
$fnavi['accounts'] = htmlspecialchars(get_section_url(ACCOUNTS_SLUG));
$fnavi['logout'] = htmlspecialchars(get_section_url(LOGOUT_SLUG));
$fnavi['recovery'] = htmlspecialchars(get_section_url(RECOVERY_SLUG));
}
Then, change this line:
Code: <?php echo $content; ?>
to this:
Code: <?php echo $fcontent; ?>
And here's the code for your navi:
Code: <ul class="nav navbar-nav">
<li><a href="<?php get_site_url(); ?>forum/">Forum</a></li>
<?php
if(!isset($_SESSION['loggedin'])) {
echo '<li ';
if($id == $fnavi['login'] || $id == $fnavi['recovery'])
echo 'class="active"';
echo ' ><a href="'.$fnavi['login'].'">Login</a></li>';
echo '<li ';
if($id == $fnavi['signup'])
echo 'class="active"';
echo ' ><a href="'.$fnavi['signup'].'">Sign up</a></li>';
} else {
echo '<li ';
if($id == $fnavi['accounts'])
echo 'class="active"';
echo ' ><a href="'.$fnavi['accounts'].'">Private</a></li>';
echo '<li ';
if($id == $fnavi['logout'])
echo 'class="active"';
echo ' ><a href="'.$fnavi['logout'].'">Logout</a></li>';
}
?>
</ul>
These changes will fix the warnings "Undefined function or variable" when the frontainer is disabled. But! this will not fix your "500 Internal Server Error" and you'll still have to fix this issue.
As a last resort, you can send a PM with credentials ;-) good luck
Posts: 14
Threads: 0
Joined: Sep 2010
Hi Bigin,
You're right.
Now, with the disabled frontainer plugin, I reach home and see menu items.
But if plugin is activated:
Fatal error: Uncaught Error: [] operator not supported for strings in /srv/vhosts/intento.ns0.it/admin/inc/theme_functions.php:475 Stack trace: #0 /srv/vhosts/intento.ns0.it/plugins/frontainer.php(389): menu_data('login') #1 /srv/vhosts/intento.ns0.it/theme/Cardinal/template.php(14): get_section_url('login') #2 /srv/vhosts/intento.ns0.it/index.php(134): include('/srv/vhosts/int...') #3 {main} thrown in /srv/vhosts/intento.ns0.it/admin/inc/theme_functions.php on line 475
If you want look in pm.
Thank you so much.
Posts: 538
Threads: 12
Joined: May 2013
Hi nicco,
yes, because GetSimple attempting to use the short array push syntax on a string there O_o Probably you use PHP 7.1 and GetSimple does not support PHP 7.1 in this release, so you'll need to change to PHP7.0 or to fix many stuff yourself.
Posts: 14
Threads: 0
Joined: Sep 2010
(2017-05-13, 02:51:45)Bigin Wrote: Hi nicco,
yes, because GetSimple attempting to use the short array push syntax on a string there O_o Probably you use PHP 7.1 and GetSimple does not support PHP 7.1 in this release, so you'll need to change to PHP7.0 or to fix many stuff yourself.
Hi Begin,
yes, I'm using 7.1.4.
Sorry if I've made you waste time, I'll have to look for another solution.
Thanks again.
Posts: 538
Threads: 12
Joined: May 2013
You're welcome! It doesn't matter what kind of plugin you will use, GetSimple does not properly run on PHP 7.1 >. But I wish you success in your work.
Posts: 3,491
Threads: 106
Joined: Mar 2010
To be fixed in 3.3.14
https://github.com/GetSimpleCMS/GetSimpleCMS/issues/1223
Posts: 538
Threads: 12
Joined: May 2013
there are more stuff to fix:
Posts: 24
Threads: 0
Joined: Apr 2020
Hi Bigin,
Thank you for your plugin, it works very well.
I just wonder where to manage users ? Directly in im.item.xml ?
And do you plan to add captcha to the forms (login, registering etc.) ?
Thx again,
Stéphane
Posts: 538
Threads: 12
Joined: May 2013
Hello Stéphane,
thx!
(2020-04-13, 03:40:16)Stéphane Wrote: I just wonder where to manage users ? Directly in im.item.xml ?
Heavens no. Just open Manager tab in admin > select Users category > a list of users will be shown.
(2020-04-13, 03:40:16)Stéphane Wrote: And do you plan to add captcha to the forms (login, registering etc.) ?
What for? A valid email address is required for registration. User must verify himself with it, and you can delete non-verified users manually. ;-)
Posts: 24
Threads: 0
Joined: Apr 2020
2020-04-13, 08:02:32
(This post was last modified: 2020-04-13, 08:04:02 by Stéphane.)
Quote:Heavens no. Just open Manager tab in admin > select Users category > a list of users will be shown.
Oh great.
Ok I'll look closer at this Item Manager, I'm sure it's a great plugin.
(2020-04-13, 03:40:16)Stéphane Wrote: Stéphane Wrote:And do you plan to add captcha to the forms (login, registering etc.) ?
Quote:What for? A valid email address is required for registration. User must verify himself with it, and you can delete non-verified users manually. ;-)
I had some troubles, few yeas ago, with a register form and tones of new fakes members...
Thank you again for your time and answer.
Posts: 538
Threads: 12
Joined: May 2013
2020-04-13, 20:32:51
(This post was last modified: 2020-04-13, 20:38:33 by Bigin.)
(2020-04-13, 08:02:32)Stéphane Wrote: I had some troubles, few yeas ago, with a register form and tones of new fakes members...
Yeah, that can be annoying. However, there are many ways to prevent this.
1. Since most bots are really very stupid and not able to handle JavaScript, so you can prevent the registration with a simple JS by submitting a string when sending the form with JS. You can then check the string when you receive the data. I promise that you will catch 99,9% bot registrations with this method.
Another one and an even simpler method is to write an ItemManager function that will check if a user has been registered for more than one day but has not yet verified with an email address, and if so, this user gets deleted:
PHP Code: /** * Remove expired user registrations * * @var int $days - Number of days allowed without verification. */ function remove_unverified( int $days = 1) { if(!isset($_POST['name']) || !isset($_POST['email'])) return;
$imanager = imanager(); $users = $imanager->getCategoryMapper()->getCategory('name=Users'); $itemMapper = $imanager->getItemMapper(); $itemMapper->alloc($users->id);
$nonVerified = $itemMapper->getSimpleItems('active=0'); if(!$nonVerified) return;
$dt = new \DateTime(); $now = new \DateTime();
foreach($nonVerified as $account) { $dt->setTimestamp($account->created); // The date was more than $days ago? if($dt->diff($now)->days > $days) { $imanager->deleteItem($account->id, $users->id); } } }
You can add it to your functions.php and call it every time the registration form is sent (a kind of lazy cron). Than, just extend your Frontainer code in functions.php as follows:
PHP Code: if(function_exists('frontainer_get_content')) { remove_unverified(); $fcontent = frontainer_get_content();
... }
Posts: 24
Threads: 0
Joined: Apr 2020
(2020-04-13, 20:32:51)Bigin Wrote: Quote:Yeah, that can be annoying. However, there are many ways to prevent this.
1. Since most bots are really very stupid and not able to handle JavaScript, so you can prevent the registration with a simple JS by submitting a string when sending the form with JS. You can then check the string when you receive the data. I promise that you will catch 99,9% bot registrations with this method.
Yes that should do the job.
I'll go too with a fake field (css hidden) that have to be empty (pseudo value=""), most bots will fill this field.
Quote:Another one and an even simpler method is to write an ItemManager function that will check if a user has been registered for more than one day but has not yet verified with an email address, and if so, this user gets deleted:
Yes that nice, thank you very much.
|