[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/phpbb/ -> user.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb;
  15  
  16  /**
  17  * Base user class
  18  *
  19  * This is the overarching class which contains (through session extend)
  20  * all methods utilised for user functionality during a session.
  21  */
  22  class user extends \phpbb\session
  23  {
  24      /**
  25       * @var \phpbb\language\language
  26       */
  27      protected $language;
  28  
  29      var $style = array();
  30      var $date_format;
  31  
  32      /**
  33      * DateTimeZone object holding the timezone of the user
  34      */
  35      public $timezone;
  36  
  37      /**
  38      * @var string Class name of datetime object
  39      */
  40      protected $datetime;
  41  
  42      var $lang_name = false;
  43      var $lang_id = false;
  44      var $lang_path;
  45      var $img_lang;
  46      var $img_array = array();
  47  
  48      /** @var bool */
  49      protected $is_setup_flag;
  50  
  51      // Able to add new options (up to id 31)
  52      var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17);
  53  
  54      /**
  55      * Constructor to set the lang path
  56      *
  57      * @param \phpbb\language\language    $lang            phpBB's Language loader
  58      * @param string                        $datetime_class    Class name of datetime class
  59      */
  60  	function __construct(\phpbb\language\language $lang, $datetime_class)
  61      {
  62          global $phpbb_root_path;
  63  
  64          $this->lang_path = $phpbb_root_path . 'language/';
  65          $this->language = $lang;
  66          $this->datetime = $datetime_class;
  67  
  68          $this->is_setup_flag = false;
  69      }
  70  
  71      /**
  72       * Returns whether user::setup was called
  73       *
  74       * @return bool
  75       */
  76  	public function is_setup()
  77      {
  78          return $this->is_setup_flag;
  79      }
  80  
  81      /**
  82       * Magic getter for BC compatibility
  83       *
  84       * Implement array access for user::lang.
  85       *
  86       * @param string    $param_name    Name of the BC component the user want to access
  87       *
  88       * @return array    The appropriate array
  89       *
  90       * @deprecated 3.2.0-dev (To be removed: 4.0.0)
  91       */
  92  	public function __get($param_name)
  93      {
  94          if ($param_name === 'lang')
  95          {
  96              return $this->language->get_lang_array();
  97          }
  98          else if ($param_name === 'help')
  99          {
 100              $help_array = $this->language->get_lang_array();
 101              return $help_array['__help'];
 102          }
 103  
 104          return array();
 105      }
 106  
 107      /**
 108      * Setup basic user-specific items (style, language, ...)
 109      */
 110  	function setup($lang_set = false, $style_id = false)
 111      {
 112          global $db, $request, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
 113          global $phpbb_dispatcher, $phpbb_container;
 114  
 115          $this->language->set_default_language($config['default_lang']);
 116  
 117          if ($this->data['user_id'] != ANONYMOUS)
 118          {
 119              $user_lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
 120              $user_date_format = $this->data['user_dateformat'];
 121              $user_timezone = $this->data['user_timezone'];
 122          }
 123          else
 124          {
 125              $lang_override = $request->variable('language', '');
 126              if ($lang_override)
 127              {
 128                  $this->set_cookie('lang', $lang_override, 0, false);
 129              }
 130              else
 131              {
 132                  $lang_override = $request->variable($config['cookie_name'] . '_lang', '', true, \phpbb\request\request_interface::COOKIE);
 133              }
 134  
 135              if ($lang_override)
 136              {
 137                  $use_lang = basename($lang_override);
 138                  $user_lang_name = (file_exists($this->lang_path . $use_lang . "/common.$phpEx")) ? $use_lang : basename($config['default_lang']);
 139                  $this->data['user_lang'] = $user_lang_name;
 140              }
 141              else
 142              {
 143                  $user_lang_name = basename($config['default_lang']);
 144              }
 145  
 146              $user_date_format = $config['default_dateformat'];
 147              $user_timezone = $config['board_timezone'];
 148  
 149              /**
 150              * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
 151              * If re-enabled we need to make sure only those languages installed are checked
 152              * Commented out so we do not loose the code.
 153  
 154              if ($request->header('Accept-Language'))
 155              {
 156                  $accept_lang_ary = explode(',', $request->header('Accept-Language'));
 157  
 158                  foreach ($accept_lang_ary as $accept_lang)
 159                  {
 160                      // Set correct format ... guess full xx_YY form
 161                      $accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
 162                      $accept_lang = basename($accept_lang);
 163  
 164                      if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
 165                      {
 166                          $user_lang_name = $config['default_lang'] = $accept_lang;
 167                          break;
 168                      }
 169                      else
 170                      {
 171                          // No match on xx_YY so try xx
 172                          $accept_lang = substr($accept_lang, 0, 2);
 173                          $accept_lang = basename($accept_lang);
 174  
 175                          if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
 176                          {
 177                              $user_lang_name = $config['default_lang'] = $accept_lang;
 178                              break;
 179                          }
 180                      }
 181                  }
 182              }
 183              */
 184          }
 185  
 186          $user_data = $this->data;
 187          $lang_set_ext = array();
 188  
 189          /**
 190          * Event to load language files and modify user data on every page
 191          *
 192          * Note: To load language file with this event, see description
 193          * of lang_set_ext variable.
 194          *
 195          * @event core.user_setup
 196          * @var    array    user_data            Array with user's data row
 197          * @var    string    user_lang_name        Basename of the user's langauge
 198          * @var    string    user_date_format    User's date/time format
 199          * @var    string    user_timezone        User's timezone, should be one of
 200          *                            http://www.php.net/manual/en/timezones.php
 201          * @var    mixed    lang_set            String or array of language files
 202          * @var    array    lang_set_ext        Array containing entries of format
 203          *                     array(
 204          *                         'ext_name' => (string) [extension name],
 205          *                         'lang_set' => (string|array) [language files],
 206          *                     )
 207          *                     For performance reasons, only load translations
 208          *                     that are absolutely needed globally using this
 209          *                     event. Use local events otherwise.
 210          * @var    mixed    style_id            Style we are going to display
 211          * @since 3.1.0-a1
 212          */
 213          $vars = array(
 214              'user_data',
 215              'user_lang_name',
 216              'user_date_format',
 217              'user_timezone',
 218              'lang_set',
 219              'lang_set_ext',
 220              'style_id',
 221          );
 222          extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
 223  
 224          $this->data = $user_data;
 225          $this->lang_name = $user_lang_name;
 226          $this->date_format = $user_date_format;
 227  
 228          $this->language->set_user_language($user_lang_name);
 229  
 230          try
 231          {
 232              $this->timezone = new \DateTimeZone($user_timezone);
 233          }
 234          catch (\Exception $e)
 235          {
 236              // If the timezone the user has selected is invalid, we fall back to UTC.
 237              $this->timezone = new \DateTimeZone('UTC');
 238          }
 239  
 240          $this->add_lang($lang_set);
 241          unset($lang_set);
 242  
 243          foreach ($lang_set_ext as $ext_lang_pair)
 244          {
 245              $this->add_lang_ext($ext_lang_pair['ext_name'], $ext_lang_pair['lang_set']);
 246          }
 247          unset($lang_set_ext);
 248  
 249          $style_request = $request->variable('style', 0);
 250          if ($style_request && (!$config['override_user_style'] || $auth->acl_get('a_styles')) && !defined('ADMIN_START'))
 251          {
 252              global $SID, $_EXTRA_URL;
 253  
 254              $style_id = $style_request;
 255              $SID .= '&amp;style=' . $style_id;
 256              $_EXTRA_URL = array('style=' . $style_id);
 257          }
 258          else
 259          {
 260              // Set up style
 261              $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
 262          }
 263  
 264          $sql = 'SELECT *
 265              FROM ' . STYLES_TABLE . " s
 266              WHERE s.style_id = $style_id";
 267          $result = $db->sql_query($sql, 3600);
 268          $this->style = $db->sql_fetchrow($result);
 269          $db->sql_freeresult($result);
 270  
 271          // Fallback to user's standard style
 272          if (!$this->style && $style_id != $this->data['user_style'])
 273          {
 274              $style_id = $this->data['user_style'];
 275  
 276              $sql = 'SELECT *
 277                  FROM ' . STYLES_TABLE . " s
 278                  WHERE s.style_id = $style_id";
 279              $result = $db->sql_query($sql, 3600);
 280              $this->style = $db->sql_fetchrow($result);
 281              $db->sql_freeresult($result);
 282          }
 283  
 284          // Fallback to board's default style
 285          if (!$this->style)
 286          {
 287              // Verify default style exists in the database
 288              $sql = 'SELECT style_id
 289                  FROM ' . STYLES_TABLE . '
 290                  WHERE style_id = ' . (int) $config['default_style'];
 291              $result = $db->sql_query($sql);
 292              $style_id = (int) $db->sql_fetchfield('style_id');
 293              $db->sql_freeresult($result);
 294  
 295              if ($style_id > 0)
 296              {
 297                  $db->sql_transaction('begin');
 298  
 299                  // Update $user row
 300                  $sql = 'SELECT *
 301                      FROM ' . STYLES_TABLE . '
 302                      WHERE style_id = ' . (int) $config['default_style'];
 303                  $result = $db->sql_query($sql);
 304                  $this->style = $db->sql_fetchrow($result);
 305                  $db->sql_freeresult($result);
 306  
 307                  // Update user style preference
 308                  $sql = 'UPDATE ' . USERS_TABLE . '
 309                      SET user_style = ' . (int) $style_id . '
 310                      WHERE user_id = ' . (int) $this->data['user_id'];
 311                  $db->sql_query($sql);
 312  
 313                  $db->sql_transaction('commit');
 314              }
 315          }
 316  
 317          // This should never happen
 318          if (!$this->style)
 319          {
 320              trigger_error($this->language->lang('NO_STYLE_DATA', $this->data['user_style'], $this->data['user_id']), E_USER_ERROR);
 321          }
 322  
 323          // Now parse the cfg file and cache it
 324          $parsed_items = $cache->obtain_cfg_items($this->style);
 325  
 326          $check_for = array(
 327              'pagination_sep'    => (string) ', '
 328          );
 329  
 330          foreach ($check_for as $key => $default_value)
 331          {
 332              $this->style[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value;
 333              settype($this->style[$key], gettype($default_value));
 334  
 335              if (is_string($default_value))
 336              {
 337                  $this->style[$key] = htmlspecialchars($this->style[$key]);
 338              }
 339          }
 340  
 341          $template->set_style();
 342  
 343          $this->img_lang = $this->lang_name;
 344  
 345          // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
 346          // After calling it we continue script execution...
 347          phpbb_user_session_handler();
 348  
 349          /**
 350          * Execute code at the end of user setup
 351          *
 352          * @event core.user_setup_after
 353          * @since 3.1.6-RC1
 354          */
 355          $phpbb_dispatcher->dispatch('core.user_setup_after');
 356  
 357          // If this function got called from the error handler we are finished here.
 358          if (defined('IN_ERROR_HANDLER'))
 359          {
 360              return;
 361          }
 362  
 363          // Disable board if the install/ directory is still present
 364          // For the brave development army we do not care about this, else we need to comment out this every time we develop locally
 365          if (!$phpbb_container->getParameter('allow_install_dir') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
 366          {
 367              // Adjust the message slightly according to the permissions
 368              if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
 369              {
 370                  $message = 'REMOVE_INSTALL';
 371              }
 372              else
 373              {
 374                  $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 375              }
 376              trigger_error($message);
 377          }
 378  
 379          // Is board disabled and user not an admin or moderator?
 380          if ($config['board_disable'] && !defined('IN_INSTALL') && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 381          {
 382              if ($this->data['is_bot'])
 383              {
 384                  send_status_line(503, 'Service Unavailable');
 385              }
 386  
 387              $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
 388              trigger_error($message);
 389          }
 390  
 391          // Is load exceeded?
 392          if ($config['limit_load'] && $this->load !== false)
 393          {
 394              if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))
 395              {
 396                  // Set board disabled to true to let the admins/mods get the proper notification
 397                  $config['board_disable'] = '1';
 398  
 399                  if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
 400                  {
 401                      if ($this->data['is_bot'])
 402                      {
 403                          send_status_line(503, 'Service Unavailable');
 404                      }
 405                      trigger_error('BOARD_UNAVAILABLE');
 406                  }
 407              }
 408          }
 409  
 410          if (isset($this->data['session_viewonline']))
 411          {
 412              // Make sure the user is able to hide his session
 413              if (!$this->data['session_viewonline'])
 414              {
 415                  // Reset online status if not allowed to hide the session...
 416                  if (!$auth->acl_get('u_hideonline'))
 417                  {
 418                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 419                          SET session_viewonline = 1
 420                          WHERE session_user_id = ' . $this->data['user_id'];
 421                      $db->sql_query($sql);
 422                      $this->data['session_viewonline'] = 1;
 423                  }
 424              }
 425              else if (!$this->data['user_allow_viewonline'])
 426              {
 427                  // the user wants to hide and is allowed to  -> cloaking device on.
 428                  if ($auth->acl_get('u_hideonline'))
 429                  {
 430                      $sql = 'UPDATE ' . SESSIONS_TABLE . '
 431                          SET session_viewonline = 0
 432                          WHERE session_user_id = ' . $this->data['user_id'];
 433                      $db->sql_query($sql);
 434                      $this->data['session_viewonline'] = 0;
 435                  }
 436              }
 437          }
 438  
 439          // Does the user need to change their password? If so, redirect to the
 440          // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
 441          if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
 442          {
 443              if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
 444              {
 445                  redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=reg_details'));
 446              }
 447          }
 448  
 449          $this->is_setup_flag = true;
 450  
 451          return;
 452      }
 453  
 454      /**
 455      * More advanced language substitution
 456      * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms.
 457      * Params are the language key and the parameters to be substituted.
 458      * This function/functionality is inspired by SHS` and Ashe.
 459      *
 460      * Example call: <samp>$user->lang('NUM_POSTS_IN_QUEUE', 1);</samp>
 461      *
 462      * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry:
 463      * Example: <samp>$user->lang(array('datetime', 'AGO'), 1)</samp> uses $user->lang['datetime']['AGO'] as language entry.
 464      *
 465      * @deprecated 3.2.0-dev (To be removed 4.0.0)
 466      */
 467  	function lang()
 468      {
 469          $args = func_get_args();
 470          return call_user_func_array(array($this->language, 'lang'), $args);
 471      }
 472  
 473      /**
 474      * Determine which plural form we should use.
 475      * For some languages this is not as simple as for English.
 476      *
 477      * @param $number        int|float   The number we want to get the plural case for. Float numbers are floored.
 478      * @param $force_rule    mixed   False to use the plural rule of the language package
 479      *                               or an integer to force a certain plural rule
 480      * @return int|bool     The plural-case we need to use for the number plural-rule combination, false if $force_rule
 481      *                        was invalid.
 482      *
 483      * @deprecated: 3.2.0-dev (To be removed: 4.0.0)
 484      */
 485  	function get_plural_form($number, $force_rule = false)
 486      {
 487          return $this->language->get_plural_form($number, $force_rule);
 488      }
 489  
 490      /**
 491      * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion)
 492      *
 493      * @param mixed $lang_set specifies the language entries to include
 494      * @param bool $use_db internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 4.0.0)
 495      * @param bool $use_help internal variable for recursion, do not use    @deprecated 3.2.0-dev (To be removed: 4.0.0)
 496      * @param string $ext_name The extension to load language from, or empty for core files
 497      *
 498      * Examples:
 499      * <code>
 500      * $lang_set = array('posting', 'help' => 'faq');
 501      * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq'))
 502      * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq'))
 503      * $lang_set = 'posting'
 504      * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting'))
 505      * </code>
 506      *
 507      * Note: $use_db and $use_help should be removed. The old function was kept for BC purposes,
 508      *         so the BC logic is handled here.
 509      *
 510      * @deprecated: 3.2.0-dev (To be removed: 4.0.0)
 511      */
 512  	function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '')
 513      {
 514          if (is_array($lang_set))
 515          {
 516              foreach ($lang_set as $key => $lang_file)
 517              {
 518                  // Please do not delete this line.
 519                  // We have to force the type here, else [array] language inclusion will not work
 520                  $key = (string) $key;
 521  
 522                  if ($key == 'db')
 523                  {
 524                      // This is never used
 525                      $this->add_lang($lang_file, true, $use_help, $ext_name);
 526                  }
 527                  else if ($key == 'help')
 528                  {
 529                      $this->add_lang($lang_file, $use_db, true, $ext_name);
 530                  }
 531                  else if (!is_array($lang_file))
 532                  {
 533                      $this->set_lang($lang_file, $use_help, $ext_name);
 534                  }
 535                  else
 536                  {
 537                      $this->add_lang($lang_file, $use_db, $use_help, $ext_name);
 538                  }
 539              }
 540              unset($lang_set);
 541          }
 542          else if ($lang_set)
 543          {
 544              $this->set_lang($lang_set, $use_help, $ext_name);
 545          }
 546      }
 547  
 548      /**
 549       * BC function for loading language files
 550       *
 551       * @deprecated 3.2.0-dev (To be removed: 4.0.0)
 552       */
 553  	private function set_lang($lang_set, $use_help, $ext_name)
 554      {
 555          if (empty($ext_name))
 556          {
 557              $ext_name = null;
 558          }
 559  
 560          if ($use_help && strpos($lang_set, '/') !== false)
 561          {
 562              $component = dirname($lang_set) . '/help_' . basename($lang_set);
 563  
 564              if ($component[0] === '/')
 565              {
 566                  $component = substr($component, 1);
 567              }
 568          }
 569          else
 570          {
 571              $component = (($use_help) ? 'help_' : '') . $lang_set;
 572          }
 573  
 574          $this->language->add_lang($component, $ext_name);
 575      }
 576  
 577      /**
 578      * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion)
 579      *
 580      * @param string $ext_name The extension to load language from, or empty for core files
 581      * @param mixed $lang_set specifies the language entries to include
 582      * @param bool $use_db internal variable for recursion, do not use
 583      * @param bool $use_help internal variable for recursion, do not use
 584      *
 585      * Note: $use_db and $use_help should be removed. Kept for BC purposes.
 586      *
 587      * @deprecated: 3.2.0-dev (To be removed: 4.0.0)
 588      */
 589  	function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false)
 590      {
 591          if ($ext_name === '/')
 592          {
 593              $ext_name = '';
 594          }
 595  
 596          $this->add_lang($lang_set, $use_db, $use_help, $ext_name);
 597      }
 598  
 599      /**
 600      * Format user date
 601      *
 602      * @param int $gmepoch unix timestamp
 603      * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i.
 604      * @param bool $forcedate force non-relative date format.
 605      *
 606      * @return mixed translated date
 607      */
 608  	function format_date($gmepoch, $format = false, $forcedate = false)
 609      {
 610          global $phpbb_dispatcher;
 611          static $utc;
 612  
 613          if (!isset($utc))
 614          {
 615              $utc = new \DateTimeZone('UTC');
 616          }
 617  
 618          $format_date_override = false;
 619          $function_arguments = func_get_args();
 620          /**
 621          * Execute code and/or override format_date()
 622          *
 623          * To override the format_date() function generated value
 624          * set $format_date_override to new return value
 625          *
 626          * @event core.user_format_date_override
 627          * @var DateTimeZone    utc Is DateTimeZone in UTC
 628          * @var array function_arguments is array comprising a function's argument list
 629          * @var string format_date_override Shall we return custom format (string) or not (false)
 630          * @since 3.2.1-RC1
 631          */
 632          $vars = array('utc', 'function_arguments', 'format_date_override');
 633          extract($phpbb_dispatcher->trigger_event('core.user_format_date_override', compact($vars)));
 634  
 635          if (!$format_date_override)
 636          {
 637              $time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
 638              $time->setTimezone($this->timezone);
 639  
 640              return $time->format($format, $forcedate);
 641          }
 642          else
 643          {
 644              return $format_date_override;
 645          }
 646      }
 647  
 648      /**
 649      * Create a \phpbb\datetime object in the context of the current user
 650      *
 651      * @since 3.1
 652      * @param string $time String in a format accepted by strtotime().
 653      * @param DateTimeZone $timezone Time zone of the time.
 654      * @return \phpbb\datetime Date time object linked to the current users locale
 655      */
 656  	public function create_datetime($time = 'now', \DateTimeZone $timezone = null)
 657      {
 658          $timezone = $timezone ?: $this->timezone;
 659          return new $this->datetime($this, $time, $timezone);
 660      }
 661  
 662      /**
 663      * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database.
 664      *
 665      * @param    string            $format        Format of the entered date/time
 666      * @param    string            $time        Date/time with the timezone applied
 667      * @param    DateTimeZone    $timezone    Timezone of the date/time, falls back to timezone of current user
 668      * @return    int            Returns the unix timestamp
 669      */
 670  	public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null)
 671      {
 672          $timezone = $timezone ?: $this->timezone;
 673          $date = \DateTime::createFromFormat($format, $time, $timezone);
 674          return ($date !== false) ? $date->format('U') : false;
 675      }
 676  
 677      /**
 678      * Get language id currently used by the user
 679      */
 680  	function get_iso_lang_id()
 681      {
 682          global $config, $db;
 683  
 684          if (!empty($this->lang_id))
 685          {
 686              return $this->lang_id;
 687          }
 688  
 689          if (!$this->lang_name)
 690          {
 691              $this->lang_name = $config['default_lang'];
 692          }
 693  
 694          $sql = 'SELECT lang_id
 695              FROM ' . LANG_TABLE . "
 696              WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'";
 697          $result = $db->sql_query($sql);
 698          $this->lang_id = (int) $db->sql_fetchfield('lang_id');
 699          $db->sql_freeresult($result);
 700  
 701          return $this->lang_id;
 702      }
 703  
 704      /**
 705      * Get users profile fields
 706      */
 707  	function get_profile_fields($user_id)
 708      {
 709          global $db;
 710  
 711          if (isset($this->profile_fields))
 712          {
 713              return;
 714          }
 715  
 716          $sql = 'SELECT *
 717              FROM ' . PROFILE_FIELDS_DATA_TABLE . "
 718              WHERE user_id = $user_id";
 719          $result = $db->sql_query_limit($sql, 1);
 720          $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row;
 721          $db->sql_freeresult($result);
 722      }
 723  
 724      /**
 725      * Specify/Get image
 726      */
 727  	function img($img, $alt = '')
 728      {
 729          $title = '';
 730  
 731          if ($alt)
 732          {
 733              $alt = $this->language->lang($alt);
 734              $title = ' title="' . $alt . '"';
 735          }
 736          return '<span class="imageset ' . $img . '"' . $title . '>' . $alt . '</span>';
 737      }
 738  
 739      /**
 740      * Get option bit field from user options.
 741      *
 742      * @param int $key option key, as defined in $keyoptions property.
 743      * @param int $data bit field value to use, or false to use $this->data['user_options']
 744      * @return bool true if the option is set in the bit field, false otherwise
 745      */
 746  	function optionget($key, $data = false)
 747      {
 748          $var = ($data !== false) ? $data : $this->data['user_options'];
 749          return phpbb_optionget($this->keyoptions[$key], $var);
 750      }
 751  
 752      /**
 753      * Set option bit field for user options.
 754      *
 755      * @param int $key Option key, as defined in $keyoptions property.
 756      * @param bool $value True to set the option, false to clear the option.
 757      * @param int $data Current bit field value, or false to use $this->data['user_options']
 758      * @return int|bool If $data is false, the bit field is modified and
 759      *                  written back to $this->data['user_options'], and
 760      *                  return value is true if the bit field changed and
 761      *                  false otherwise. If $data is not false, the new
 762      *                  bitfield value is returned.
 763      */
 764  	function optionset($key, $value, $data = false)
 765      {
 766          $var = ($data !== false) ? $data : $this->data['user_options'];
 767  
 768          $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var);
 769  
 770          if ($data === false)
 771          {
 772              if ($new_var != $var)
 773              {
 774                  $this->data['user_options'] = $new_var;
 775                  return true;
 776              }
 777              else
 778              {
 779                  return false;
 780              }
 781          }
 782          else
 783          {
 784              return $new_var;
 785          }
 786      }
 787  
 788      /**
 789      * Function to make the user leave the NEWLY_REGISTERED system group.
 790      * @access public
 791      */
 792  	function leave_newly_registered()
 793      {
 794          if (empty($this->data['user_new']))
 795          {
 796              return false;
 797          }
 798  
 799          if (!function_exists('remove_newly_registered'))
 800          {
 801              global $phpbb_root_path, $phpEx;
 802  
 803              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 804          }
 805          if ($group = remove_newly_registered($this->data['user_id'], $this->data))
 806          {
 807              $this->data['group_id'] = $group;
 808  
 809          }
 810          $this->data['user_permissions'] = '';
 811          $this->data['user_new'] = 0;
 812  
 813          return true;
 814      }
 815  
 816      /**
 817      * Returns all password protected forum ids the user is currently NOT authenticated for.
 818      *
 819      * @return array     Array of forum ids
 820      * @access public
 821      */
 822  	function get_passworded_forums()
 823      {
 824          global $db;
 825  
 826          $sql = 'SELECT f.forum_id, fa.user_id
 827              FROM ' . FORUMS_TABLE . ' f
 828              LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa
 829                  ON (fa.forum_id = f.forum_id
 830                      AND fa.session_id = '" . $db->sql_escape($this->session_id) . "')
 831              WHERE f.forum_password <> ''";
 832          $result = $db->sql_query($sql);
 833  
 834          $forum_ids = array();
 835          while ($row = $db->sql_fetchrow($result))
 836          {
 837              $forum_id = (int) $row['forum_id'];
 838  
 839              if ($row['user_id'] != $this->data['user_id'])
 840              {
 841                  $forum_ids[$forum_id] = $forum_id;
 842              }
 843          }
 844          $db->sql_freeresult($result);
 845  
 846          return $forum_ids;
 847      }
 848  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1