forked from e107inc/e107
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_model.php
3182 lines (2794 loc) · 75.1 KB
/
user_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2011 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* User Model
*
* $URL$
* $Id$
*/
/**
* @package e107
* @subpackage e107_handlers
* @version $Id$
* @author SecretR
*
* Front-end User Models
*/
if (!defined('e107_INIT'))
{
exit;
}
/**
*
*/
class e_user_model extends e_admin_model
{
/**
* Describes all model data, used as _FIELD_TYPE array as well
* @var array
*/
protected $_data_fields = array(
'user_id' => 'integer',
'user_name' => 'string',
'user_loginname' => 'string',
'user_customtitle' => 'string',
'user_password' => 'string',
'user_sess' => 'string',
'user_email' => 'string',
'user_signature' => 'string',
'user_image' => 'string',
'user_hideemail' => 'integer',
'user_join' => 'integer',
'user_lastvisit' => 'integer',
'user_currentvisit' => 'integer',
'user_lastpost' => 'integer',
'user_chats' => 'integer',
'user_comments' => 'integer',
'user_ip' => 'string',
'user_ban' => 'integer',
'user_prefs' => 'string',
'user_visits' => 'integer',
'user_admin' => 'integer',
'user_login' => 'string',
'user_class' => 'string',
'user_perms' => 'string',
'user_realm' => 'string',
'user_pwchange' => 'integer',
'user_xup' => 'string',
);
/**
* Validate required fields
* @var array
*/
protected $_validation_rules = array(
'user_name' => array('string', '1', 'LAN_USER_01', 'LAN_USER_HELP_01'), // TODO - regex
'user_loginname' => array('string', '1', 'LAN_USER_02', 'LAN_USER_HELP_02'), // TODO - regex
'user_password' => array('compare', '5', 'LAN_PASSWORD', 'LAN_USER_HELP_05'), // TODO - pref - modify it somewhere below - prepare_rules()?
'user_email' => array('email', '', 'LAN_EMAIL', 'LAN_USER_HELP_08'),
);
/**
* Validate optional fields - work in progress, not working yet
* @var array
*/
protected $_optional_rules = array(
'user_customtitle' => array('string', '1', 'LAN_USER_01'), // TODO - regex
);
/**
* @see e_model
* @var string
*/
protected $_db_table = 'user';
/**
* @see e_model
* @var string
*/
protected $_field_id = 'user_id';
/**
* @see e_model
* @var string
*/
protected $_message_stack = 'user';
/**
* User class as set in user Adminsitration
*
* @var integer
*/
protected $_memberlist_access = null;
/**
* Extended data
*
* @var e_user_extended_model
*/
protected $_extended_model = null;
/**
* Extended structure
*
* @var e_user_extended_structure
*/
protected $_extended_structure = null;
/**
* User preferences model
* @var e_user_pref
*/
protected $_user_config = null;
/**
* User model of current editor
* @var e_user_model
*/
protected $_editor = null;
protected $_class_list;
/**
* Constructor
* @param array $data
* @return void
*/
public function __construct($data = array())
{
$this->_memberlist_access = e107::getPref('memberlist_access');
parent::__construct($data);
}
/**
* Always return integer
*
* @see e107_handlers/e_model#getId()
*/
public function getId()
{
return (integer) parent::getId();
}
/**
* Try display name, fall back to login name when empty (shouldn't happen)
*/
final public function getName($anon = false)
{
if($this->isUser())
{
return ($this->get('user_name') ? $this->get('user_name') : $this->get('user_loginname'));
}
return $anon;
}
/**
* Display name getter. Use it as DB field name will be changed soon.
*/
final public function getDisplayName()
{
return $this->get('user_name');
}
/**
* Login name getter. Use it as DB field name will be changed soon.
*/
final public function getLoginName()
{
return $this->get('user_loginname');
}
/**
* Real name getter. Use it as DB field name will be changed soon.
* @param bool $strict if false, fall back to Display name when empty
* @return mixed
*/
final public function getRealName($strict = false)
{
if($strict) return $this->get('user_login');
return ($this->get('user_login') ? $this->get('user_login') : $this->get('user_name'));
}
/**
* @return false|int
*/
final public function getAdminId()
{
return ($this->isAdmin() ? $this->getId() : false);
}
/**
* @return false|mixed
*/
final public function getAdminName()
{
return ($this->isAdmin() ? $this->get('user_name') : false);
}
/**
* @return false|mixed
*/
final public function getAdminEmail()
{
return ($this->isAdmin() ? $this->get('user_email') : false);
}
/**
* @return false|mixed
*/
final public function getAdminPwchange()
{
return ($this->isAdmin() ? $this->get('user_pwchange') : false);
}
/**
* @return false|mixed
*/
final public function getAdminPerms()
{
return ($this->isAdmin() ? $this->get('user_perms') : false);
}
/**
* @return mixed|string
*/
final public function getTimezone()
{
// If timezone is not set, we return an empty string in order to use the
// default timezone is set for e107.
return ($this->get('user_timezone') ? $this->get('user_timezone') : '');
}
/**
* DEPRECATED - will be removed or changed soon (see e_session)
* @return string
*/
public function getToken()
{
if(null === $this->get('user_token'))
{
//$this->set('user_token', md5($this->get('user_password').$this->get('user_lastvisit').$this->get('user_pwchange').$this->get('user_class')));
$this->set('user_token', e107::getSession()->getFormToken(false));
}
return $this->get('user_token');
}
/**
* @return string
*/
public static function randomKey()
{
return md5(uniqid(rand(), 1));
}
/**
* @return false
*/
public function isCurrent()
{
return false;
}
/**
* @return bool
*/
final public function isAdmin()
{
return ($this->get('user_admin') ? true : false);
}
/**
* @return bool
*/
final public function isNewUser()
{
$new_user_period = e107::getPref('user_new_period', 0);
if(empty($new_user_period)) { return false; }
return ($this->get('user_join') > strtotime($new_user_period . " days ago"));
}
/**
* @param $userAgent
* @return bool
*/
final public function isBot($userAgent = null)
{
if($userAgent === null && isset($_SERVER['HTTP_USER_AGENT']))
{
$userAgent = $_SERVER['HTTP_USER_AGENT'];
}
if(empty($userAgent))
{
return false;
}
$botlist = array(
// old list.
"Teoma", "alexa", "froogle", "Gigabot", "inktomi",
"looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
"Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
"crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
"msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
"Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
"Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
"Butterfly","Twitturls","Me.dium","Twiceler",
// new list.
'80legs',
'ABACHOBot',
'Accoona-AI-Agent',
'AddSugarSpiderBot',
'AnyApexBot',
'applebot',
'Arachmo',
'B-l-i-t-z-B-O-T',
'Baiduspider',
'BecomeBot',
'BeslistBot',
'BillyBobBot',
'Bimbot',
'bingbot',
'BlitzBot',
'boitho.com-dc',
'boitho.com-robot',
'btbot',
'CatchBot',
'Cerberian Drtrs',
'Charlotte',
'ConveraCrawler',
'cosmos',
'Covario',
'DataparkSearch',
'DiamondBot',
'Discobot',
'dotnetdot', // DotBot
'EARTHCOM.info',
'EmeraldShield.com WebBot',
'envolk[ITS]spider',
'EsperanzaBot',
'Exabot',
'FAST Enterprise',
'fastsearch', // FAST Enterprise
'FAST-WebCrawler',
'FDSE robot',
'findlinks',
'FurlBot',
'FyberSpider',
'g2crawler',
'Gaisbot',
'GalaxyBot',
'genieBot',
'Gigabot',
'Girafabot',
'Googlebot',
'Googlebot-Image',
'GurujiBot',
'HappyFunBot',
'hl_ftien_spider',
'holmes',
'htdig',
'iaskspider',
'ia_archiver',
'iCCrawler',
'ichiro',
'igdeSpyder',
'IRLbot',
'IssueCrawler',
'Jaxified Bot',
'Jyxobot',
'KoepaBot',
'L.webis',
'LapozzBot',
'larbin',
'LDSpider',
'LexxeBot',
'Linguee Bot',
'LinkWalker',
'lmspider',
'lwp-trivial',
'mabontland',
'magpie-crawler',
'Mediapartners-Google',
'MJ12bot',
'MLBot',
'Mnogosearch',
'mogimogi',
'MojeekBot',
'Moreoverbot',
'Morning Paper',
'msnbot',
'msrbot',
'MVAClient',
'mxbot',
'NetResearchServer',
'NetSeer',
'NewsGator',
'NG-Search',
'nicebot',
'noxtrumbot',
'Nusearch Spider',
'NutchCVS',
'Nymesis',
'obot',
'oegp',
'omgilibot',
'OmniExplorer_Bot',
'OOZBOT',
'Orbiter',
'PageBites',
'Peew',
'petalbot',
'Pinterestbot',
'polybot',
'Pompos',
'PostPost',
'psbot',
'PycURL',
'Qseero',
'radian',
'RAMPyBot',
'RufusBot',
'SandCrawler',
'SBIder',
'ScoutJet',
'Scrubby',
'SearchSight',
'Seekbot',
'semanticdiscovery',
'SemrushBot',
'Sensis Web Crawler',
'SEOChat::Bot',
'SeznamBot',
'Shim-Crawler',
'ShopWiki',
'Shoula robot',
'Silk',
'silk',
'Sitebot',
'Snappy',
'sogou spider',
'Sosospider',
'Speedy Spider',
'Sqworm',
'StackRambler',
'suggybot',
'SurveyBot',
'SynooBot',
'Teoma',
'TerrawizBot',
'TheSuBot',
'Thumbnail.CZ robot',
'TinEye',
'truwoGPS',
'TurnitinBot',
'TweetedTimes Bot',
'TwengaBot',
'updated',
'Urlfilebot',
'Vagabondo',
'VoilaBot',
'Vortex',
'voyager',
'VYU2',
'webcollage',
'Websquash.com',
'wf84',
'WoFindeIch Robot',
'WomlpeFactory',
'Xaldon_WebSpider',
'yacy',
'Yahoo! Slurp',
'Yahoo! Slurp China',
'YahooSeeker',
'YahooSeeker-Testing',
'YandexBot',
'YandexImages',
'YandexMetrika',
'Yasaklibot',
'Yeti',
'YodaoBot',
'yoogliFetchAgent',
'YoudaoBot',
'Zao',
'Zealbot',
'zspider',
'ZyBorg'
);
foreach($botlist as $bot)
{
if(stripos($userAgent, $bot) !== false){ return true; }
}
return false;
}
/**
* @return bool
*/
final public function isMainAdmin()
{
return $this->checkAdminPerms('0');
}
/**
* @return bool
*/
final public function isUser()
{
return ($this->getId() ? true : false);
}
/**
* @return bool
*/
final public function isGuest()
{
return ($this->getId() ? false : true);
}
/**
* @return bool
*/
final public function hasBan()
{
return ((integer) $this->get('user_ban') === 1);
}
/**
* @return bool
*/
final public function hasRestriction()
{
return ((integer) $this->get('user_ban') !== 0);
}
/**
* @return bool
*/
public function hasEditor()
{
return (null !== $this->_editor);
}
/**
* @return $this
*/
final protected function _setClassList()
{
$this->_class_list = array();
if ($this->isUser())
{
if ($this->get('user_class'))
{
// list of all 'inherited' user classes, convert elements to integer
$this->_class_list = array_map('intval', e107::getUserClass()->get_all_user_classes($this->get('user_class'), true));
}
$this->_class_list[] = e_UC_MEMBER;
if($this->isNewUser())
{
$this->_class_list[] = e_UC_NEWUSER;
}
if ($this->isAdmin())
{
$this->_class_list[] = e_UC_ADMIN;
}
if ($this->isMainAdmin())
{
$this->_class_list[] = e_UC_MAINADMIN;
}
}
else
{
$this->_class_list[] = e_UC_GUEST;
if($this->isBot())
{
$this->_class_list[] = e_UC_BOTS;
}
}
$this->_class_list[] = e_UC_READONLY;
$this->_class_list[] = e_UC_PUBLIC;
// unique, rebuild indexes
$this->_class_list = array_merge(array_unique($this->_class_list));
return $this;
}
/**
* @param bool $toString
* @return string
*/
final public function getClassList($toString = false)
{
if (null === $this->_class_list)
{
$this->_setClassList();
}
return ($toString ? implode(',', $this->_class_list) : $this->_class_list);
}
/**
* @return string
*/
final public function getClassRegex()
{
return '(^|,)('.str_replace(',', '|', $this->getClassList(true)).')(,|$)';
}
/**
* @param $class
* @param bool $allowMain
* @return bool
*/
final public function checkClass($class, $allowMain = true)
{
// FIXME - replace check_class() here
return (($allowMain && $this->isMainAdmin()) || check_class($class, $this->getClassList(), 0));
}
/**
* Check if this user has the provided admin permissions.
*
* @param string $perm_str The serialized requested access code or codes which will match if any of the codes are in
* the admin user's admin permissions.
* This is a pipe-delimited (`|`) list of access codes.
* Example: `C|4`
* @return bool true if the user has the matching admin permissions, false otherwise.
*/
final public function checkAdminPerms($perm_str)
{
if(!$this->isAdmin())
{
return false;
}
$ap = $this->getAdminPerms();
return e_userperms::simulateHasAdminPerms($perm_str, $ap);
}
/**
* Check if this user has permissions to administer the given plugin.
*
* @param string $plugin_name The name of the plugin, not the path like in {@see getperms()}.
* @return bool true if the user has admin permissions for the plugin, false otherwise.
*/
final public function checkPluginAdminPerms($plugin_name)
{
$sql = e107::getDb('psql');
$ap = $this->getAdminPerms();
return e_userperms::simulateHasPluginAdminPerms($sql, $plugin_name, $ap);
}
/**
* @param $class
* @return bool
*/
final public function checkEditorPerms($class = '')
{
if (!$this->hasEditor())
return false;
$editor = $this->getEditor();
if ('' !== $class)
return ($editor->isAdmin() && $editor->checkClass($class));
return $editor->isAdmin();
}
/**
* Check passed value against current user token
* DEPRECATED - will be removed or changed soon (see e_core_session)
* @param string $token md5 sum of e.g. posted token
* @return boolean
*/
final public function checkToken($token)
{
$utoken = $this->getToken();
return (null !== $utoken && $token === md5($utoken));
}
/**
* Bad but required (BC) method of retrieving all user data
* It's here to be used from get_user_data() core function.
* DON'T USE THEM BOTH unless you have VERY good reason to do it.
*
* @return array
*/
public function getUserData()
{
// revised - don't call extended object, no permission checks, just return joined user data
$ret = $this->getData();
// $ret = array_merge($this->getExtendedModel()->getExtendedData(), $this->getData());
if ($ret['user_perms'] == '0.') $ret['user_perms'] = '0';
$ret['user_baseclasslist'] = $ret['user_class'];
$ret['user_class'] = $this->getClassList(true);
return $ret;
}
/**
* Check if given field name is present in core user table structure
*
* @param string $field
* @param boolean $short
* @return boolean
*/
public function isCoreField($field, $short = true)
{
if($short) $field = 'user_'.$field;
return isset($this->_data_fields[$field]);
}
/**
* Check if given field name is present in extended user table structure
*
* @param string $field
* @param boolean $short
* @return boolean
*/
public function isExtendedField($field, $short = true)
{
if($short) $field = 'user_'.$field;
if($this->isCoreField($field, false))
{
return false;
}
return $this->getExtendedModel()->isField($field, false);
}
/**
* Get User value from core user table.
* This method doesn't perform any read permission cheks.
*
* @param string $field
* @param mixed $default
* @param boolean $short if true, 'user_' prefix will be added to field name
* @return mixed if field is not part of core user table returns null by default
*/
public function getCore($field, $default = null, $short = true)
{
if($short) $field = 'user_'.$field;
if($this->isCoreField($field, false)) return $this->get($field, $default);
return $default;
}
/**
* Set User value (core user field).
* This method doesn't perform any write permission cheks.
*
* @param string $field
* @param mixed $value
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $strict if false no Applicable check will be made
* @return e_user_model
*/
public function setCore($field, $value, $short = true, $strict = false)
{
if($short) $field = 'user_'.$field;
if($this->isCoreField($field, false)) $this->set($field, $value, $strict);
return $this;
}
/**
* Get User extended value.
* This method doesn't perform any read permission cheks.
*
* @param string $field
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $raw get raw DB values (no SQL query)
* @return mixed
*/
public function getExtended($field, $short = true, $raw = true)
{
return $this->getExtendedModel()->getSystem($field, $short, $raw);
}
/**
* Set User extended value.
* This method doesn't perform any write permission cheks.
*
* @param string $field
* @param mixed $value
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $strict if false no Applicable check will be made
* @return e_user_model
*/
public function setExtended($field, $value, $short = true, $strict = false)
{
$this->getExtendedModel()->setSystem($field, $value, $short, $strict);
return $this;
}
/**
* Get User extended value after checking read permissions against current Editor
*
* @param string $field
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $raw get raw DB values (no SQL query)
* @return mixed
*/
public function getExtendedFront($field, $short = true, $raw = false)
{
return $this->getExtendedModel()->getValue($field, $short, $raw);
}
/**
* Set User extended value after checking write permissions against current Editor.
*
* @param string $field
* @param mixed $value
* @param boolean $short if true, 'user_' prefix will be added to field name
* @return e_user_model
*/
public function setExtendedFront($field, $value, $short = true)
{
$this->getExtendedModel()->setValue($field, $value, $short);
return $this;
}
/**
* Transparent front-end getter. It performs all required read/applicable permission checks
* against current editor/user. It doesn't distinguish core and extended fields.
* It grants BC.
* It's what you'd need in all front-end parsing code (e.g. shortcodes)
*
* @param string $field
* @param mixed $default
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $rawExtended get raw DB values (no SQL query) - used only for extended fields
* @return mixed if field is not readable returns null by default
*/
public function getValue($field, $default = null, $short = true, $rawExtended = false)
{
if($short)
{
$mfield = $field;
$field = 'user_'.$field;
}
else
{
$mfield = substr($field, 5);
}
// check for BC/override method first e.g. getSingatureValue($default, $system = false, $rawExtended);
$method = 'get'.ucfirst($mfield).'Value';
if(method_exists($this, $method)) return $this->$method($default, false, $rawExtended);
if($this->isCoreField($field, false))
{
if(!$this->isReadable($field)) return $default;
return $this->getCore($field, $default, false);
}
return $this->getExtendedFront($field, false, $rawExtended);
}
/**
* Transparent front-end setter. It performs all required write/applicable permission checks
* against current editor/user. It doesn't distinguish core and extended fields.
* It grants BC.
* It's what you'd need on all user front-end manipulation events (e.g. user settings page related code)
* NOTE: untrusted data should be provided via setPosted() method!
*
* @param string $field
* @param mixed $value
* @param boolean $short if true, 'user_' prefix will be added to field name
* @return e_user_model
*/
public function setValue($field, $value, $short = true)
{
if($short)
{
$mfield = $field;
$field = 'user_'.$field;
}
else
{
$mfield = substr($field, 5);
}
// check for BC/override method first e.g. setSingatureValue($value, $system = false);
$method = 'set'.ucfirst($mfield).'Value';
if(method_exists($this, $method))
{
$this->$method($value, false);
return $this;
}
if($this->isCoreField($field, false))
{
if($this->isWritable($field)) $this->setCore($field, $value, false, true);
}
else
{
$this->setExtendedFront($field, $value, false);
}
return $this;
}
/**
* Transparent system getter. It doesn't perform any read/applicable permission checks
* against current editor/user. It doesn't distinguish core and extended fields.
* It grants BC.
* It's here to serve in your application logic.
*
* @param string $field
* @param mixed $default
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $rawExtended get raw DB values (no SQL query) - used only for extended fields
* @return mixed
*/
public function getSystem($field, $default = null, $short = true, $rawExtended = true)
{
if($short)
{
$mfield = $field;
$field = 'user_'.$field;
}
else
{
$mfield = substr($field, 5);
}
// check for BC/override method first e.g. getSingatureValue($default, $system = true, $rawExtended);
$method = 'get'.ucfirst($mfield).'Value';
if(method_exists($this, $method)) return $this->$method($default, true, $rawExtended);
if($this->isCoreField($field, false))
{
return $this->getCore($field, $default, false);
}
return $this->getExtended($field, false, $rawExtended);
}
/**
* Transparent front-end setter. It doesn't perform any write/applicable permission checks
* against current editor/user. It doesn't distinguish core and extended fields.
* It's here to serve in your application logic.
* NOTE: untrusted data should be provided via setPosted() method!
*
* @param string $field
* @param mixed $value
* @param boolean $short if true, 'user_' prefix will be added to field name
* @param boolean $strict if false no Applicable check will be made
* @return e_user_model
*/
public function setSystem($field, $value, $short = true, $strict = false)
{
if($short)
{
$mfield = $field;
$field = 'user_'.$field;
}
else
{
$mfield = substr($field, 5);
}
// check for BC/override method first e.g. setSingatureValue($value, $system = true);
$method = 'set'.ucfirst($mfield).'Value';
if(method_exists($this, $method))
{
$this->$method($value, true);
return $this;
}
if($this->isCoreField($field, false))
{
$this->setCore($field, $value, false, $strict);