[ Index ]

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1