Guest User

seo_url

a guest
Jan 8th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 43.41 KB | None | 0 0
  1.  
  2. /**
  3.  *
  4.  * @package       Ultimate SEO URL phpBB SEO
  5.  * @version       $Id: phpbb_seo_class.php 236 2010-03-03 08:20:36Z dcz $
  6.  * @copyright (c) 2006 - 2010 www.phpbb-seo.com
  7.  * @license       http://www.opensource.org/licenses/rpl1.5.txt Reciprocal Public License 1.5
  8.  *
  9.  */
  10. /**
  11.  * @ignore
  12.  */
  13. if (!defined('IN_PHPBB')) {
  14.     exit;
  15. }
  16. require($phpbb_root_path . "phpbb_seo/includes/setup_phpbb_seo.$phpEx");
  17.  
  18. /**
  19.  * phpBB_SEO Class
  20.  * www.phpBB-SEO.com
  21.  * @package Ultimate SEO URL phpBB SEO
  22.  */
  23. class phpbb_seo extends setup_phpbb_seo
  24. {
  25.     var $version         = '0.6.4';
  26.     var $modrtype        = 2; // We set it to mixed as a default value
  27.     var $seo_path        = [];
  28.     var $seo_url         = ['forum' => [], 'topic' => [], 'user' => [], 'username' => [], 'group' => [], 'file' => []];
  29.     var $phpbb_filter    = [
  30.         'forum' => ['st' => 0, 'sk' => 't', 'sd' => 'd'],
  31.         'topic' => ['st' => 0, 'sk' => 't', 'sd' => 'a', 'hilit' => ''],
  32.         'search' => ['st' => 0, 'sk' => 't', 'sd' => 'd', 'ch' => ''],
  33.     ];
  34.     var $seo_stop_files  = ['posting' => 1, 'faq' => 1, 'ucp' => 1, 'swatch' => 1, 'mcp' => 1, 'style' => 1, 'cron' => 1];
  35.     var $seo_stop_vars   = ['view=', 'mark=', 'watch=', 'hash='];
  36.     var $seo_stop_dirs   = [];
  37.     var $seo_delim       = ['forum' => '-f', 'topic' => '-t', 'user' => '-u', 'group' => '-g', 'start' => '-', 'sr' => '-', 'file' => '/'];
  38.     var $seo_ext         = ['forum' => '.html', 'topic' => '.html', 'post' => '.html', 'user' => '.html', 'group' => '.html', 'index' => '', 'global_announce' => '/', 'leaders' => '.html', 'atopic' => '.html', 'utopic' => '.html', 'npost' => '.html', 'urpost' => '.html', 'pagination' => '.html', 'gz_ext' => ''];
  39.     var $seo_static      = ['forum' => 'forum', 'topic' => 'topic', 'post' => 'post', 'user' => 'member', 'group' => 'group', 'index' => '', 'global_announce' => 'announces', 'leaders' => 'the-team', 'atopic' => 'active-topics', 'utopic' => 'unanswered', 'npost' => 'newposts', 'urpost' => 'unreadposts', 'pagination' => 'page', 'gz_ext' => '.gz'];
  40.     var $file_hbase      = [];
  41.     var $get_vars        = [];
  42.     var $path            = '';
  43.     var $start           = '';
  44.     var $filename        = '';
  45.     var $file            = '';
  46.     var $url_in          = '';
  47.     var $url             = '';
  48.     var $page_url        = '';
  49.     var $seo_opt         = [
  50.         'url_rewrite' => false,
  51.         'modrtype' => 2, 'sql_rewrite' => false, 'profile_inj' => false, 'profile_vfolder' => false, 'profile_noids' => false, 'rewrite_usermsg' => false, 'rewrite_files' => false, 'rem_sid' => false, 'rem_hilit' => true, 'rem_small_words' => false, 'virtual_folder' => false, 'virtual_root' => false, 'cache_layer' => true, 'rem_ids' => false,];
  52.     var $rewrite_method  = [];
  53.     var $paginate_method = [];
  54.     var $seo_cache       = [];
  55.     var $cache_config    = [];
  56.     var $RegEx           = [];
  57.     var $sftpl           = [];
  58.     var $url_replace     = [];
  59.  
  60.     /**
  61.      * constuctor
  62.      */
  63.     function phpbb_seo()
  64.     {
  65.         global $phpEx, $config, $phpbb_root_path;
  66.         // fix for an interesting bug with parse_str http://bugs.php.net/bug.php?id=48697
  67.         // and apparently, the bug is still here in php5.3
  68.         @ini_set("mbstring.internal_encoding", 'UTF-8');
  69.         // Nothing should be edited here, please do your custom settings in the
  70.         // phpbb_seo/includes/phpbb_seo_modules.php instead to make your updates easier.
  71.         // reset the rewrite_method for $phpbb_root_path
  72.         $this->rewrite_method[$phpbb_root_path] = [];
  73.         // phpBB files must be treated a bit differently
  74.         $this->seo_static['file']       = [ATTACHMENT_CATEGORY_NONE => 'file', ATTACHMENT_CATEGORY_IMAGE => 'image', ATTACHMENT_CATEGORY_WM => 'wm', ATTACHMENT_CATEGORY_RM => 'rm', ATTACHMENT_CATEGORY_THUMB => 'image', ATTACHMENT_CATEGORY_FLASH => 'flash', ATTACHMENT_CATEGORY_QUICKTIME => 'qt'];
  75.         $this->seo_static['file_index'] = 'resources';
  76.         $this->seo_static['thumb']      = 'thumb';
  77.         // Options that may be bypassed by the cached settings.
  78.         $this->cache_config['dynamic_options'] = array_keys($this->seo_opt); // Do not change
  79.         // copyright notice, do not change
  80.         $this->cache_config['dynamic_options']['copyrights'] = $this->seo_opt['copyrights'] = ['img' => true, 'txt' => '', 'title' => ''];
  81.         // Caching config
  82.         $this->seo_opt['cache_folder'] = 'phpbb_seo/cache/'; // Folder where the cache file is stored
  83.         define('SEO_CACHE_PATH', rtrim(phpbb_realpath($phpbb_root_path . $this->seo_opt['cache_folder']), '/') . '/'); // do not change
  84.         $this->seo_opt['topic_type']        = []; // do not change
  85.         $this->seo_opt['topic_last_page']   = []; // do not change
  86.         $this->cache_config['cache_enable'] = true; // do not change
  87.         $this->cache_config['rem_ids']      = $this->seo_opt['rem_ids']; // do not change, set up above
  88.         $this->cache_config['files']        = ['forum' => 'phpbb_cache.' . $phpEx, 'htaccess' => '.htaccess'];
  89.         $this->cache_config['cached']       = false; // do not change
  90.         $this->cache_config['forum']        = []; // do not change
  91.         $this->cache_config['topic']        = []; // do not change
  92.         $this->cache_config['settings']     = []; // do not change
  93.         // --> DOMAIN SETTING <-- //
  94.         // Path Settings, only rely on DB
  95.         $server_protocol                = ($config['server_protocol']) ? $config['server_protocol'] : (($config['cookie_secure']) ? 'https://' : 'http://');
  96.         $server_name                    = trim($config['server_name'], '/ ');
  97.         $server_port                    = max(0, (int)$config['server_port']);
  98.         $server_port                    = ($server_port && $server_port <> 80) ? ':' . $server_port : '';
  99.         $script_path                    = trim($config['script_path'], './ ');
  100.         $script_path                    = (empty($script_path)) ? '' : $script_path . '/';
  101.         $this->seo_path['root_url']     = strtolower($server_protocol . $server_name . $server_port . '/');
  102.         $this->seo_path['phpbb_urlR']   = $this->seo_path['phpbb_url'] = $this->seo_path['root_url'] . $script_path;
  103.         $this->seo_path['phpbb_script'] = $script_path;
  104.  
  105.         // --> Custom str_Replace arrays, to handle special cases properly
  106.         $this->seo_opt['url_find']    = [utf8_chr(260), utf8_chr(261),  // Aa
  107.             utf8_chr(262), utf8_chr(263), // Cc
  108.             utf8_chr(280), utf8_chr(281), // Ee
  109.             utf8_chr(321), utf8_chr(322), // Ll
  110.             utf8_chr(323), utf8_chr(324), // Nn
  111.             utf8_chr(379), utf8_chr(380), // Zz
  112.             utf8_chr(377), utf8_chr(378), // Zz
  113.             utf8_chr(346), utf8_chr(347), // Ss
  114.         ];
  115.         $this->seo_opt['url_replace'] = ['a', 'a', 'c', 'c', 'e', 'e', 'l', 'l', 'n', 'n', 'z', 'z', 'z', 'z', 's', 's'];
  116.  
  117.         $this->seo_path['phpbb_files'] = $this->seo_path['phpbb_url'] . 'download/';
  118.         $this->seo_path['canonical']   = '';
  119.         // magic quotes, do it like this in case phpbb_seo class is not started in common.php
  120.         if (!defined('STRIP')) {
  121.             if (version_compare(PHP_VERSION, '6.0.0-dev', '<')) {
  122.                 if (get_magic_quotes_gpc()) {
  123.                     define('SEO_STRIP', true);
  124.                 }
  125.             }
  126.         } elseif (STRIP) {
  127.             define('SEO_STRIP', true);
  128.         }
  129.         // File setting
  130.         $this->seo_req_uri();
  131.         $this->seo_opt['seo_base_href'] = $this->seo_opt['req_file'] = $this->seo_opt['req_self'] = '';
  132.         if ($script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF')) {
  133.             // From session.php
  134.             // Replace backslashes and doubled slashes (could happen on some proxy setups)
  135.             $this->seo_opt['req_self'] = str_replace(['\\', '//'], '/', $script_name);
  136.             // basenamed page name (for example: index)
  137.             $this->seo_opt['req_file'] = urlencode(htmlspecialchars(str_replace(".$phpEx", '', basename($this->seo_opt['req_self']))));
  138.         }
  139.         // Load settings from phpbb_seo/includes/phpbb_seo_modules.php
  140.         $this->init_phpbb_seo();
  141.         $this->seo_path['phpbb_filesR'] = $this->seo_path['phpbb_urlR'] . $this->seo_static['file_index'] . $this->seo_delim['file'];
  142.         // see if we have some custom replacement
  143.         if (!empty($this->url_replace)) {
  144.             $this->url_replace = [
  145.                 'find' => array_keys($this->url_replace),
  146.                 'replace' => array_values($this->url_replace)
  147.             ];
  148.         }
  149.         $this->seo_opt['topic_per_page'] = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page']; // do not change
  150.         // Array of the filenames that require the use of a base href tag.
  151.         $this->file_hbase = array_merge(['viewtopic' => $this->seo_path['phpbb_url'], 'viewforum' => $this->seo_path['phpbb_url'], 'memberlist' => $this->seo_path['phpbb_url'], 'search' => $this->seo_path['phpbb_url']], $this->file_hbase);
  152.         // Stop dirs
  153.         $this->seo_stop_dirs = array_merge([$phpbb_root_path . 'adm/' => false], $this->seo_stop_dirs);
  154.         // Rewrite functions array : array( 'path' => array('file_name' => 'function_name'));
  155.         // Warning, this way of doing things is path aware, this implies path to be properly sent to append_sid()
  156.         // Allow to add options without slowing down the URL rewriting process
  157.         $this->rewrite_method[$phpbb_root_path]                       = array_merge(
  158.             [
  159.                 'viewtopic' => 'viewtopic',
  160.                 'viewforum' => 'viewforum',
  161.                 'index' => 'index',
  162.                 'memberlist' => 'memberlist',
  163.                 'search' => $this->seo_opt['rewrite_usermsg'] ? 'search' : '',
  164.             ],
  165.             $this->rewrite_method[$phpbb_root_path]
  166.         );
  167.         $this->rewrite_method[$phpbb_root_path . 'download/']['file'] = $this->seo_opt['rewrite_files'] ? 'phpbb_files' : '';
  168.         $this->paginate_method                                        = array_merge(
  169.             [
  170.                 'topic' => $this->seo_ext['topic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  171.                 'forum' => $this->seo_ext['forum'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  172.                 'group' => $this->seo_ext['group'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  173.                 'user' => $this->seo_ext['user'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  174.                 'atopic' => $this->seo_ext['atopic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  175.                 'utopic' => $this->seo_ext['utopic'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  176.                 'npost' => $this->seo_ext['npost'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  177.                 'urpost' => $this->seo_ext['urpost'] === '/' ? 'rewrite_pagination_page' : 'rewrite_pagination',
  178.             ],
  179.             $this->paginate_method
  180.         );
  181.         $this->RegEx                                                  = array_merge(
  182.             [
  183.                 'topic' => [
  184.                     'check' => '`^' . ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '(' . $this->seo_static['topic'] . '|[a-z0-9_-]+' . $this->seo_delim['topic'] . ')$`i',
  185.                     'match' => '`^((([a-z0-9_-]+)(' . $this->seo_delim['forum'] . '([0-9]+))?/)?(' . $this->seo_static['topic'] . '(?!=' . $this->seo_delim['topic'] . ')|.+(?=' . $this->seo_delim['topic'] . '))(' . $this->seo_delim['topic'] . ')?)([0-9]+)$`i',
  186.                     'parent' => 2,
  187.                     'parent_id' => 5,
  188.                     'title' => 6,
  189.                     'id' => 8,
  190.                     'url' => 1,
  191.                 ],
  192.                 'forum' => [
  193.                     'check' => $this->modrtype >= 2 ? '`^[a-z0-9_-]+(' . $this->seo_delim['forum'] . '[0-9]+)?$`i' : '`^' . $this->seo_static['forum'] . '[0-9]+$`i',
  194.                     'match' => '`^((' . $this->seo_static['forum'] . '|.+)(' . $this->seo_delim['forum'] . '([0-9]+))?)$`i',
  195.                     'title' => '\2',
  196.                     'id' => '\4',
  197.                 ],
  198.             ],
  199.             $this->RegEx
  200.         );
  201.         // preg_replace() patterns for format_url()
  202.         // One could want to add |th|horn after |slash, but I'm not sure that Þ should be replaced with t and Ð with e
  203.         $this->RegEx['url_find']    = ['`&([a-z]+)(acute|grave|circ|cedil|tilde|uml|lig|ring|caron|slash);`i', '`&(amp;)?[^;]+;`i', '`[^a-z0-9]`i']; // Do not remove : deaccentuation, html/xml entities & non a-z chars
  204.         $this->RegEx['url_replace'] = ['\1', '-', '-'];
  205.         if ($this->seo_opt['rem_small_words']) {
  206.             $this->RegEx['url_find'][]    = '`(^|-)[a-z0-9]{1,2}(?=-|$)`i';
  207.             $this->RegEx['url_replace'][] = '-';
  208.         }
  209.         $this->RegEx['url_find'][]    = '`[-]+`'; // Do not remove : multi hyphen reduction
  210.         $this->RegEx['url_replace'][] = '-';
  211.         // $1 parent : string/
  212.         // $2 title / url : topic-title / forum-url-fxx
  213.         // $3 id
  214.         $this->sftpl = array_merge(
  215.             [
  216.                 'topic' => ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '%2$s' . $this->seo_delim['topic'] . '%3$s',
  217.                 'topic_smpl' => ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . $this->seo_static['topic'] . '%3$s',
  218.                 'forum' => $this->modrtype >= 2 ? '%2$s' : $this->seo_static['forum'] . '%3$s',
  219.                 'group' => $this->seo_opt['profile_inj'] ? '%2$s' . $this->seo_delim['group'] . '%3$s' : $this->seo_static['group'] . '%3$s',
  220.             ],
  221.             $this->sftpl
  222.         );
  223.         if ($this->seo_opt['url_rewrite'] && !defined('ADMIN_START') && isset($this->file_hbase[$this->seo_opt['req_file']])) {
  224.             $this->seo_opt['seo_base_href'] = '<base href="' . $this->file_hbase[$this->seo_opt['req_file']] . '"/>';
  225.         }
  226.         return;
  227.     }
  228.  
  229.     /**
  230.      * will make sure that configured options are consistent
  231.      * @access private
  232.      */
  233.     function check_config()
  234.     {
  235.         $this->modrtype = max(0, (int)$this->modrtype);
  236.         // For profiles and user messages pages, if we do not inject, we do not get rid of ids
  237.         $this->seo_opt['profile_noids'] = $this->seo_opt['profile_inj'] ? $this->seo_opt['profile_noids'] : false;
  238.         // If profile noids ...
  239.         if ($this->seo_opt['profile_noids']) {
  240.             $this->seo_ext['user'] = '/';
  241.         }
  242.         // Profile ans user messages virtual folder
  243.         if ($this->seo_opt['profile_vfolder']) {
  244.             $this->seo_ext['user'] = '/';
  245.         }
  246.         $this->seo_delim['sr'] = $this->seo_ext['user'] == '/' ? '/' : $this->seo_delim['sr'];
  247.         // If we use virtual folder, we need '/' at the end of the forum URLs
  248.         if ($this->seo_opt['virtual_folder']) {
  249.             $this->seo_ext['forum'] = $this->seo_ext['global_announce'] = '/';
  250.         }
  251.         // If the forum cache is not activated
  252.         if (!$this->seo_opt['cache_layer']) {
  253.             $this->seo_opt['rem_ids'] = false;
  254.         }
  255.         // virtual root option
  256.         if ($this->seo_opt['virtual_root'] && $this->seo_path['phpbb_script']) {
  257.             // virtual root is available and activated
  258.             $this->seo_path['phpbb_urlR'] = $this->seo_path['root_url'];
  259.             $this->file_hbase['index']    = $this->seo_path['phpbb_url'];
  260.             $this->seo_static['index']    = empty($this->seo_static['index']) ? 'forum' : $this->seo_static['index'];
  261.         } else {
  262.             // virtual root is not used or usable
  263.             $this->seo_opt['virtual_root'] = false;
  264.         }
  265.         $this->seo_ext['index'] = empty($this->seo_static['index']) ? '' : (empty($this->seo_ext['index']) ? '.html' : $this->seo_ext['index']);
  266.         // In case url rewriting is deactivated
  267.         if (!$this->seo_opt['url_rewrite'] || $this->modrtype == 0) {
  268.             $this->seo_opt['sql_rewrite']     = false;
  269.             $this->seo_opt['zero_dupe']['on'] = false;
  270.         }
  271.     }
  272.     // --> URL rewriting functions <--
  273.  
  274.     /**
  275.      * format_url( $url, $type = 'topic' )
  276.      * Prepare Titles for URL injection
  277.      */
  278.     function format_url($url, $type = 'topic')
  279.     {
  280.         $url = preg_replace('`\[.*\]`U', '', $url);
  281.         //polsklie
  282.         $url = str_replace($this->seo_opt['url_find'], $this->seo_opt['url_replace'], $url);
  283.         if (isset($this->url_replace['find'])) {
  284.             $url = str_replace($this->url_replace['find'], $this->url_replace['replace'], $url);
  285.         }
  286.         $url = htmlentities($url, ENT_COMPAT, 'UTF-8');
  287.         $url = preg_replace($this->RegEx['url_find'], $this->RegEx['url_replace'], $url);
  288.         $url = strtolower(trim($url, '-'));
  289.         return empty($url) ? $type : $url;
  290.     }
  291.  
  292.     /**
  293.      * set_url( $url, $id = 0, $type = 'forum', $parent = '' )
  294.      * Prepare url first part and checks cache
  295.      */
  296.     function set_url($url, $id = 0, $type = 'forum', $parent = '')
  297.     {
  298.         if (empty($this->seo_url[$type][$id])) {
  299.             return $this->generateSeoUrl($url, $id, $type, $parent);
  300.         }
  301.         return $this->seo_url[$type][$id];
  302.     }
  303.  
  304.     /**
  305.      * prepare_url( $type, $title, $id, $parent = '', $smpl = false )
  306.      * Prepare url first part
  307.      */
  308.     function prepare_url($type, $title, $id, $parent = '', $smpl = false)
  309.     {
  310.         return empty($this->seo_url[$type][$id]) ? ($this->seo_url[$type][$id] = sprintf($this->sftpl[$type . ($smpl ? '_smpl' : '')], $parent, !$smpl ? $this->format_url($title, $this->seo_static[$type]) : '', $id)) : $this->seo_url[$type][$id];
  311.     }
  312.  
  313.     /**
  314.      * set_title( $type, $title, $id, $parent = '' )
  315.      * Set title for url injection
  316.      */
  317.     function set_title($type, $title, $id, $parent = '')
  318.     {
  319.         return empty($this->seo_url[$type][$id]) ? ($this->seo_url[$type][$id] = ($parent ? $parent . '/' : '') . $this->format_url($title, $this->seo_static[$type])) : $this->seo_url[$type][$id];
  320.     }
  321.  
  322.     /**
  323.      * get_url_info($type, $url, $info = 'title')
  324.      * Get info from url (title, id, parent etc ...)
  325.      */
  326.     function get_url_info($type, $url, $info = 'title')
  327.     {
  328.         $url = trim($url, '/ ');
  329.         if (preg_match($this->RegEx[$type]['match'], $url, $matches)) {
  330.             return !empty($matches[$this->RegEx[$type][$info]]) ? $matches[$this->RegEx[$type][$info]] : '';
  331.         }
  332.         return '';
  333.     }
  334.  
  335.     /**
  336.      * check_url( $type, $url, $parent = '')
  337.      * Validate a prepared url
  338.      */
  339.     function check_url($type, $url, $parent = '')
  340.     {
  341.         if (empty($url)) {
  342.             return false;
  343.         }
  344.         $parent = !empty($parent) ? (string)$parent : '[a-z0-9/_-]+';
  345.         return !empty($this->RegEx[$type]['check']) ? preg_match(sprintf($this->RegEx[$type]['check'], $parent), $url) : false;
  346.     }
  347.  
  348.     /**
  349.      * prepare_iurl( $data, $type, $parent = '' )
  350.      * Prepare url first part (not for forums) with SQL based URL rewriting
  351.      */
  352.     function prepare_iurl($data, $type, $parent = '')
  353.     {
  354.         $id = max(0, (int)$data[$type . '_id']);
  355.         if (empty($this->seo_url[$type][$id])) {
  356.             if (!empty($data[$type . '_url'])) {
  357.                 return ($this->seo_url[$type][$id] = $data[$type . '_url'] . $id);
  358.             } else {
  359.                 return ($this->seo_url[$type][$id] = sprintf($this->sftpl[$type . ($this->modrtype > 2 ? '' : '_smpl')], $parent, $this->modrtype > 2 ? $this->format_url($data[$type . '_title'], $this->seo_static[$type]) : '', $id));
  360.             }
  361.         }
  362.         return $this->seo_url[$type][$id];
  363.     }
  364.  
  365.     /**
  366.      * drop_sid( $url )
  367.      * drop the sid's in url
  368.      */
  369.     function drop_sid($url)
  370.     {
  371.         return (strpos($url, 'sid=') !== false) ? trim(preg_replace(['`&(amp;)?sid=[a-z0-9]*(&amp;|&)?`', '`(\?)sid=[a-z0-9]*`'], ['\2', '\1'], $url), '?') : $url;
  372.     }
  373.  
  374.     /**
  375.      * set_user_url( $username, $user_id = 0 )
  376.      * Prepare profile url
  377.      */
  378.     function set_user_url($username, $user_id = 0)
  379.     {
  380.         if (empty($this->seo_url['user'][$user_id])) {
  381.             $username                             = strip_tags($username);
  382.             $this->seo_url['username'][$username] = $user_id;
  383.             if ($this->seo_opt['profile_inj']) {
  384.                 if ($this->seo_opt['profile_noids']) {
  385.                     $this->seo_url['user'][$user_id] = $this->seo_static['user'] . '/' . $this->seo_url_encode($username);
  386.                 } else {
  387.                     $this->seo_url['user'][$user_id] = $this->format_url($username, $this->seo_delim['user']) . $this->seo_delim['user'] . $user_id;
  388.                 }
  389.             } else {
  390.                 $this->seo_url['user'][$user_id] = $this->seo_static['user'] . $user_id;
  391.             }
  392.         }
  393.     }
  394.  
  395.     /**
  396.      * seo_url_encode( $url )
  397.      * custom urlencoding
  398.      */
  399.     function seo_url_encode($url)
  400.     {
  401.         // can be faster to return $url directly if you do not allow more chars than
  402.         // [a-zA-Z0-9_\.-] in your usernames
  403.         // return $url;
  404.         // Here we hanlde the "&", "/", "+" and "#" case proper ( http://www.php.net/urlencode => http://issues.apache.org/bugzilla/show_bug.cgi?id=34602 )
  405.         static $find = ['&', '/', '#', '+'];
  406.         static $replace = ['%26', '%2F', '%23', '%2b'];
  407.         return rawurlencode(str_replace($find, $replace, utf8_normalize_nfc(htmlspecialchars_decode(str_replace('&amp;amp;', '%26', rawurldecode($url))))));
  408.     }
  409.  
  410.     /**
  411.      * url_rewrite($url, $params = false, $is_amp = true, $session_id = false)
  412.      * builds and Rewrite URLs.
  413.      * Allow adding of many more cases than just the
  414.      * regular phpBB URL rewritting without slowing down the process.
  415.      * Mimics append_sid with some shortcuts related to how url are rewritten
  416.      */
  417.     function url_rewrite($url, $params = false, $is_amp = true, $session_id = false)
  418.     {
  419.         global $phpEx, $user, $_SID, $_EXTRA_URL, $phpbb_root_path;
  420.         $qs             = $anchor = '';
  421.         $this->get_vars = [];
  422.         $amp_delim      = ($is_amp) ? '&amp;' : '&';
  423.         if (strpos($url, '#') !== false) {
  424.             list($url, $anchor) = explode('#', $url, 2);
  425.             $anchor = '#' . $anchor;
  426.         }
  427.         @list($this->path, $qs) = explode('?', $url, 2);
  428.         if (is_array($params)) {
  429.             if (!empty($params['#'])) {
  430.                 $anchor = '#' . $params['#'];
  431.                 unset($params['#']);
  432.             }
  433.             $qs .= ($qs ? $amp_delim : '') . $this->query_string($params, $amp_delim, '');
  434.         } elseif ($params) {
  435.             if (strpos($params, '#') !== false) {
  436.                 list($params, $anchor) = explode('#', $params, 2);
  437.                 $anchor = '#' . $anchor;
  438.             }
  439.             $qs .= ($qs ? $amp_delim : '') . $params;
  440.         }
  441.         // Appending custom url parameter?
  442.         if (!empty($_EXTRA_URL)) {
  443.             $qs .= ($qs ? $amp_delim : '') . implode($amp_delim, $_EXTRA_URL);
  444.         }
  445.         // Sid ?
  446.         if ($session_id === false && !empty($_SID)) {
  447.             $qs .= ($qs ? $amp_delim : '') . "sid=$_SID";
  448.         } else if ($session_id) {
  449.             $qs .= ($qs ? $amp_delim : '') . "sid=$session_id";
  450.         }
  451.         // Build vanilla URL
  452.         if (preg_match("`\.[a-z0-9]+$`i", $this->path)) {
  453.             $this->file = basename($this->path);
  454.             $this->path = ltrim(str_replace($this->file, '', $this->path), '/');
  455.         } else {
  456.             $this->file = '';
  457.             $this->path = ltrim($this->path, '/');
  458.         }
  459.         $this->url_in = $this->file . ($qs ? '?' . $qs : '');
  460.         $url          = $this->path . $this->url_in . $anchor;
  461.         if (isset($this->seo_cache[$url])) {
  462.             return $this->seo_cache[$url];
  463.         }
  464.         if (!$this->seo_opt['url_rewrite'] || defined('ADMIN_START') || isset($this->seo_stop_dirs[$this->path])) {
  465.             return ($this->seo_cache[$url] = $url);
  466.         }
  467.         $this->filename = trim(str_replace(".$phpEx", '', $this->file));
  468.         if (isset($this->seo_stop_files[$this->filename])) {
  469.             // add full url
  470.             $url = $this->path == $phpbb_root_path ? $this->seo_path['phpbb_url'] . preg_replace('`^' . $phpbb_root_path . '`', '', $url) : $url;
  471.             return ($this->seo_cache[$url] = $url);
  472.         }
  473.         parse_str(str_replace('&amp;', '&', $qs), $this->get_vars);
  474.         // strp slashes if necessary
  475.         if (defined('SEO_STRIP')) {
  476.             $this->get_vars = array_map([&$this, 'stripslashes'], $this->get_vars);
  477.         }
  478.         if (empty($user->data['is_registered'])) {
  479.             if ($this->seo_opt['rem_sid']) {
  480.                 unset($this->get_vars['sid']);
  481.             }
  482.             if ($this->seo_opt['rem_hilit']) {
  483.                 unset($this->get_vars['hilit']);
  484.             }
  485.         }
  486.         $this->url = $this->file;
  487.         if (!empty($this->rewrite_method[$this->path][$this->filename])) {
  488.             $this->{$this->rewrite_method[$this->path][$this->filename]}();
  489.             return ($this->seo_cache[$url] = $this->path . $this->url . $this->query_string($this->get_vars, $amp_delim, '?') . $anchor);
  490.         } else {
  491.             return ($this->seo_cache[$url] = $url);
  492.         }
  493.     }
  494.  
  495.     /**
  496.      * URL rewritting for viewtopic.php
  497.      * With Virtual Folder Injection
  498.      * @access private
  499.      */
  500.     function viewtopic()
  501.     {
  502.         global $phpbb_root_path;
  503.         $this->filter_url($this->seo_stop_vars);
  504.         $this->path = $this->seo_path['phpbb_urlR'];
  505.         if (!empty($this->get_vars['p'])) {
  506.             $this->url = $this->seo_static['post'] . $this->get_vars['p'] . $this->seo_ext['post'];
  507.             unset($this->get_vars['p'], $this->get_vars['f'], $this->get_vars['t'], $this->get_vars['start']);
  508.             return;
  509.         }
  510.         if (isset($this->get_vars['t']) && !empty($this->seo_url['topic'][$this->get_vars['t']])) {
  511.             // Filter default params
  512.             $this->filter_get_var($this->phpbb_filter['topic']);
  513.             $this->{$this->paginate_method['topic']}($this->seo_ext['topic']);
  514.             $this->url = $this->seo_url['topic'][$this->get_vars['t']] . $this->start;
  515.             unset($this->get_vars['t'], $this->get_vars['f'], $this->get_vars['p']);
  516.             return;
  517.         } else if (!empty($this->get_vars['t'])) {
  518.             // Filter default params
  519.             $this->filter_get_var($this->phpbb_filter['topic']);
  520.             $this->{$this->paginate_method['topic']}($this->seo_ext['topic']);
  521.             $this->url = $this->seo_static['topic'] . $this->get_vars['t'] . $this->start;
  522.             unset($this->get_vars['t'], $this->get_vars['f'], $this->get_vars['p']);
  523.             return;
  524.         }
  525.         $this->path = $this->seo_path['phpbb_url'];
  526.         return;
  527.     }
  528.  
  529.     /**
  530.      * URL rewritting for viewforum.php
  531.      * @access private
  532.      */
  533.     function viewforum()
  534.     {
  535.         global $phpbb_root_path;
  536.         $this->path = $this->seo_path['phpbb_urlR'];
  537.         $this->filter_url($this->seo_stop_vars);
  538.         if (isset($this->get_vars['f']) && !empty($this->seo_url['forum'][$this->get_vars['f']])) {
  539.             // Filter default params
  540.             $this->filter_get_var($this->phpbb_filter['forum']);
  541.             $this->{$this->paginate_method['forum']}($this->seo_ext['forum']);
  542.             $this->url = $this->seo_url['forum'][$this->get_vars['f']] . $this->start;
  543.             unset($this->get_vars['f']);
  544.             return;
  545.         } else if (!empty($this->get_vars['f'])) {
  546.             // Filter default params
  547.             $this->filter_get_var($this->phpbb_filter['forum']);
  548.             $this->{$this->paginate_method['forum']}($this->seo_ext['forum']);
  549.             $this->url = $this->seo_static['forum'] . $this->get_vars['f'] . $this->start;
  550.             unset($this->get_vars['f']);
  551.             return;
  552.         }
  553.         $this->path = $this->seo_path['phpbb_url'];
  554.         return;
  555.     }
  556.  
  557.     /**
  558.      * URL rewritting for memberlist.php
  559.      * with nicknames and group name injection
  560.      * @access private
  561.      */
  562.     function memberlist()
  563.     {
  564.         global $phpbb_root_path;
  565.         $this->path = $this->seo_path['phpbb_urlR'];
  566.         if (@$this->get_vars['mode'] === 'viewprofile' && !@empty($this->seo_url['user'][$this->get_vars['u']])) {
  567.             $this->url = $this->seo_url['user'][$this->get_vars['u']] . $this->seo_ext['user'];
  568.             unset($this->get_vars['mode'], $this->get_vars['u']);
  569.             return;
  570.         } elseif (@$this->get_vars['mode'] === 'group' && !@empty($this->seo_url['group'][$this->get_vars['g']])) {
  571.             $this->{$this->paginate_method['group']}($this->seo_ext['group']);
  572.             $this->url = $this->seo_url['group'][$this->get_vars['g']] . $this->start;
  573.             unset($this->get_vars['mode'], $this->get_vars['g']);
  574.             return;
  575.         } elseif (@$this->get_vars['mode'] === 'leaders') {
  576.             $this->url = $this->seo_static['leaders'] . $this->seo_ext['leaders'];
  577.             unset($this->get_vars['mode']);
  578.             return;
  579.         }
  580.         $this->path = $this->seo_path['phpbb_url'];
  581.         return;
  582.     }
  583.  
  584.     /**
  585.      * URL rewritting for search.php
  586.      * @access private
  587.      */
  588.     function search()
  589.     {
  590.         global $phpbb_root_path;
  591.         if (isset($this->get_vars['fid'])) {
  592.             $this->get_vars = [];
  593.             $this->url      = $this->url_in;
  594.             return;
  595.         }
  596.         $this->path = $this->seo_path['phpbb_urlR'];
  597.         $user_id    = !empty($this->get_vars['author_id']) ? $this->get_vars['author_id'] : (isset($this->seo_url['username'][rawurldecode(@$this->get_vars['author'])]) ? $this->seo_url['username'][rawurldecode(@$this->get_vars['author'])] : 0);
  598.         if ($user_id && isset($this->seo_url['user'][$user_id])) {
  599.             // Filter default params
  600.             $this->filter_get_var($this->phpbb_filter['search']);
  601.             $this->{$this->paginate_method['user']}($this->seo_ext['user']);
  602.             $sr        = (@$this->get_vars['sr'] == 'topics') ? 'topics' : 'posts';
  603.             $this->url = $this->seo_url['user'][$user_id] . $this->seo_delim['sr'] . $sr . $this->start;
  604.             unset($this->get_vars['author_id'], $this->get_vars['author'], $this->get_vars['sr']);
  605.             return;
  606.         } elseif ($this->seo_opt['profile_noids'] && !empty($this->get_vars['author'])) {
  607.             // Filter default params
  608.             $this->filter_get_var($this->phpbb_filter['search']);
  609.             $this->rewrite_pagination_page();
  610.             $sr        = (@$this->get_vars['sr'] == 'topics') ? '/topics' : '/posts';
  611.             $this->url = $this->seo_static['user'] . '/' . $this->seo_url_encode($this->get_vars['author']) . $sr . $this->start;
  612.             unset($this->get_vars['author'], $this->get_vars['author_id'], $this->get_vars['sr']);
  613.             return;
  614.         } elseif (!empty($this->get_vars['search_id'])) {
  615.             switch ($this->get_vars['search_id']) {
  616.                 case 'active_topics':
  617.                     $this->filter_get_var($this->phpbb_filter['search']);
  618.                     $this->{$this->paginate_method['atopic']}($this->seo_ext['atopic']);
  619.                     $this->url = $this->seo_static['atopic'] . $this->start;
  620.                     unset($this->get_vars['search_id'], $this->get_vars['sr']);
  621.                     if (@$this->get_vars['st'] == 7) {
  622.                         unset($this->get_vars['st']);
  623.                     }
  624.                     return;
  625.                 case 'unanswered':
  626.                     $this->filter_get_var($this->phpbb_filter['search']);
  627.                     $this->{$this->paginate_method['utopic']}($this->seo_ext['utopic']);
  628.                     $this->url = $this->seo_static['utopic'] . $this->start;
  629.                     unset($this->get_vars['search_id']);
  630.                     if (@$this->get_vars['sr'] == 'topics') {
  631.                         unset($this->get_vars['sr']);
  632.                     }
  633.                     return;
  634.                 case 'egosearch':
  635.                     global $user;
  636.                     $this->set_user_url($user->data['username'], $user->data['user_id']);
  637.                     $this->url = $this->seo_url['user'][$user->data['user_id']] . $this->seo_delim['sr'] . 'topics' . $this->seo_ext['user'];
  638.                     unset($this->get_vars['search_id']);
  639.                     return;
  640.                 case 'newposts':
  641.                     $this->filter_get_var($this->phpbb_filter['search']);
  642.                     $this->{$this->paginate_method['npost']}($this->seo_ext['npost']);
  643.                     $this->url = $this->seo_static['npost'] . $this->start;
  644.                     unset($this->get_vars['search_id']);
  645.                     if (@$this->get_vars['sr'] == 'topics') {
  646.                         unset($this->get_vars['sr']);
  647.                     }
  648.                     return;
  649.                 case 'unreadposts':
  650.                     $this->filter_get_var($this->phpbb_filter['search']);
  651.                     $this->{$this->paginate_method['urpost']}($this->seo_ext['urpost']);
  652.                     $this->url = $this->seo_static['urpost'] . $this->start;
  653.                     unset($this->get_vars['search_id']);
  654.                     if (@$this->get_vars['sr'] == 'topics') {
  655.                         unset($this->get_vars['sr']);
  656.                     }
  657.                     return;
  658.             }
  659.         }
  660.         $this->path = $this->seo_path['phpbb_url'];
  661.         return;
  662.     }
  663.  
  664.     /**
  665.      * URL rewritting for download/file.php
  666.      * @access private
  667.      */
  668.     function phpbb_files()
  669.     {
  670.         $this->filter_url($this->seo_stop_vars);
  671.         $this->path = $this->seo_path['phpbb_filesR'];
  672.         if (isset($this->get_vars['id']) && !empty($this->seo_url['file'][$this->get_vars['id']])) {
  673.             $this->url = $this->seo_url['file'][$this->get_vars['id']];
  674.             if (!empty($this->get_vars['t'])) {
  675.                 $this->url .= $this->seo_delim['file'] . $this->seo_static['thumb'];
  676.             } /*else if (@$this->get_vars['mode'] == 'view') {
  677.                 $this->url .= $this->seo_delim['file'] . 'view';
  678.             }*/
  679.             $this->url .= $this->seo_delim['file'] . $this->get_vars['id'];
  680.             unset($this->get_vars['id'], $this->get_vars['t'], $this->get_vars['mode']);
  681.             return;
  682.         }
  683.         $this->path = $this->seo_path['phpbb_files'];
  684.         return;
  685.     }
  686.  
  687.     /**
  688.      * URL rewritting for index.php
  689.      * @access private
  690.      */
  691.     function index()
  692.     {
  693.         $this->path = $this->seo_path['phpbb_urlR'];
  694.         if ($this->filter_url($this->seo_stop_vars)) {
  695.             $this->url = $this->seo_static['index'] . $this->seo_ext['index'];
  696.             return;
  697.         }
  698.         $this->path = $this->seo_path['phpbb_url'];
  699.         return;
  700.     }
  701.  
  702.     /**
  703.      * Returns true if the user can edit urls
  704.      * @access public
  705.      */
  706.     function url_can_edit($forum_id = 0)
  707.     {
  708.         global $user, $auth;
  709.         if (empty($this->seo_opt['sql_rewrite']) || empty($user->data['is_registered'])) {
  710.             return false;
  711.         }
  712.         if ($auth->acl_get('a_')) {
  713.             return true;
  714.         }
  715.         // un comment to grant url edit perm to moderators in at least a forums
  716.         /*if ($auth->acl_getf_global('m_')) {
  717.             return true;
  718.         }*/
  719.         $forum_id = max(0, (int)$forum_id);
  720.         if ($forum_id && $auth->acl_get('m_', $forum_id)) {
  721.             return true;
  722.         }
  723.         return false;
  724.     }
  725.  
  726.     /**
  727.      * Will break if a $filter pattern is foundin $url.
  728.      * Example $filter = array("view=", "mark=");
  729.      * @access private
  730.      */
  731.     function filter_url($filter = [])
  732.     {
  733.         foreach ($filter as $patern) {
  734.             if (strpos($this->url_in, $patern) !== false) {
  735.                 $this->get_vars = [];
  736.                 $this->url      = $this->url_in;
  737.                 return false;
  738.             }
  739.         }
  740.         return true;
  741.     }
  742.  
  743.     /**
  744.      * Will unset all default var stored in $filter array.
  745.      * Example $filter = array('st' => 0, 'sk' => 't', 'sd' => 'a', 'hilit' => '');
  746.      * @access private
  747.      */
  748.     function filter_get_var($filter = [])
  749.     {
  750.         if (!empty($this->get_vars)) {
  751.             foreach ($this->get_vars as $paramkey => $paramval) {
  752.                 if (isset($filter[$paramkey])) {
  753.                     if ($filter[$paramkey] == $this->get_vars[$paramkey] || !isset($this->get_vars[$paramkey])) {
  754.                         unset($this->get_vars[$paramkey]);
  755.                     }
  756.                 }
  757.             }
  758.         }
  759.         return;
  760.     }
  761.  
  762.     /**
  763.      * Appends the GET vars in the query string
  764.      * @access public
  765.      */
  766.     function query_string($get_vars = [], $amp_delim = '&amp;', $url_delim = '?')
  767.     {
  768.         if (empty($get_vars)) {
  769.             return '';
  770.         }
  771.         $params = [];
  772.         foreach ($get_vars as $key => $value) {
  773.             if (is_array($value)) {
  774.                 foreach ($value as $k => $v) {
  775.                     $params[] = $key . '[' . $k . ']=' . $v;
  776.                 }
  777.             } else {
  778.                 $params[] = $key . (!trim($value) ? '' : '=' . $value);
  779.             }
  780.         }
  781.         return $url_delim . implode($amp_delim, $params);
  782.     }
  783.  
  784.     /**
  785.      * rewrite pagination, simple
  786.      * -xx.html
  787.      */
  788.     function rewrite_pagination($suffix)
  789.     {
  790.         $this->start = $this->seo_start(@$this->get_vars['start']) . $suffix;
  791.         unset($this->get_vars['start']);
  792.     }
  793.  
  794.     /**
  795.      * rewrite pagination, virtual folder
  796.      * /pagexx.html
  797.      */
  798.     function rewrite_pagination_page()
  799.     {
  800.         $this->start = '/' . $this->seo_start_page(@$this->get_vars['start']);
  801.         unset($this->get_vars['start']);
  802.     }
  803.  
  804.     /**
  805.      * Returns usable start param
  806.      * -xx
  807.      */
  808.     function seo_start($start)
  809.     {
  810.         return ($start >= 1) ? $this->seo_delim['start'] . (int)$start : '';
  811.     }
  812.  
  813.     /**
  814.      * Returns usable start param
  815.      * pagexx.html
  816.      * Only used in virtual folder mode
  817.      */
  818.     function seo_start_page($start)
  819.     {
  820.         return ($start >= 1) ? $this->seo_static['pagination'] . (int)$start . $this->seo_ext['pagination'] : '';
  821.     }
  822.  
  823.     /**
  824.      * Returns the full REQUEST_URI
  825.      */
  826.     function seo_req_uri()
  827.     {
  828.         if (!empty($_SERVER['HTTP_X_REWRITE_URL'])) { // IIS  isapi_rewrite
  829.             $this->seo_path['uri'] = ltrim($_SERVER['HTTP_X_REWRITE_URL'], '/');
  830.         } elseif (!empty($_SERVER['REQUEST_URI'])) { // Apache mod_rewrite
  831.             $this->seo_path['uri'] = ltrim($_SERVER['REQUEST_URI'], '/');
  832.         } else { // no mod rewrite
  833.             $this->seo_path['uri'] = ltrim($_SERVER['SCRIPT_NAME'], '/') . ((!empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '');
  834.         }
  835.         $this->seo_path['uri'] = str_replace('%26', '&', rawurldecode($this->seo_path['uri']));
  836.         // workaround for FF default iso encoding
  837.         if (!$this->is_utf8($this->seo_path['uri'])) {
  838.             $this->seo_path['uri'] = utf8_normalize_nfc(utf8_recode($this->seo_path['uri'], 'iso-8859-1'));
  839.         }
  840.         $this->seo_path['uri'] = $this->seo_path['root_url'] . $this->seo_path['uri'];
  841.         return $this->seo_path['uri'];
  842.     }
  843.  
  844.     /**
  845.      * seo_end() : The last touch function
  846.      * Note : This mod is going to help your site a lot in Search Engines
  847.      * We request that you keep this copyright notice as specified in the licence.
  848.      * If You really cannot put this link, you should at least provide us with one visible
  849.      * (can be small but visible) link on your home page or your forum Index using this code for example :
  850.      * <a href="http://www.phpbb-seo.com/" title="Search Engine Optimization">phpBB SEO</a>
  851.      */
  852.     function seo_end($return = false)
  853.     {
  854.         global $user, $config;
  855.         if (empty($this->seo_opt['copyrights']['title'])) {
  856.             $this->seo_opt['copyrights']['title'] = strpos($config['default_lang'], 'fr') !== false ? 'Optimisation du R&eacute;f&eacute;rencement' : 'Search Engine Optimization';
  857.         }
  858.         if (empty($this->seo_opt['copyrights']['txt'])) {
  859.             $this->seo_opt['copyrights']['txt'] = 'phpBB SEO';
  860.         }
  861.         if ($this->seo_opt['copyrights']['img']) {
  862.             $output = '<br /><a href="http://www.phpbb-seo.com/" title="' . $this->seo_opt['copyrights']['title'] . '"><img src="' . $this->seo_path['phpbb_url'] . 'images/phpbb-seo.png" alt="' . $this->seo_opt['copyrights']['txt'] . '"/></a>';
  863.         } else {
  864.             $output = '<br /><a href="http://www.phpbb-seo.com/" title="' . $this->seo_opt['copyrights']['title'] . '">' . $this->seo_opt['copyrights']['txt'] . '</a>';
  865.         }
  866.         if ($return) {
  867.             return $output;
  868.         } else {
  869.             $user->lang['TRANSLATION_INFO'] .= $output;
  870.         }
  871.         return;
  872.     }
  873.     // -> Cache functions
  874.  
  875.     /**
  876.      * forum_id(&$forum_id, $forum_uri = '')
  877.      * will tell the forum id from the uri or the forum_uri GET var by checking the cache.
  878.      */
  879.     function get_forum_id(&$forum_id, $forum_uri = '')
  880.     {
  881.         if (empty($forum_uri)) {
  882.             $forum_uri = request_var('forum_uri', '');
  883.             unset($_GET['forum_uri'], $_REQUEST['forum_uri']);
  884.         }
  885.         if (empty($forum_uri)) {
  886.             return 0;
  887.         }
  888.         if ($id = @array_search($forum_uri, $this->cache_config['forum'])) {
  889.             $forum_id = max(0, (int)$id);
  890.         } elseif ($id = $this->get_url_info('forum', $forum_uri, 'id')) {
  891.             $forum_id = max(0, (int)$id);
  892.         }
  893.         return $forum_id;
  894.     }
  895.  
  896.     /**
  897.      * check_cache() will tell if the required file exists.
  898.      * @access private
  899.      */
  900.     function check_cache($type = 'forum', $from_bkp = false)
  901.     {
  902.         $file = SEO_CACHE_PATH . @$this->cache_config['files'][$type];
  903.         if (!$this->cache_config['cache_enable'] || !isset($this->cache_config['files'][$type]) || !file_exists($file)) {
  904.             $this->cache_config['cached'] = false;
  905.             return false;
  906.         }
  907.         include($file);
  908.         if (is_array($this->cache_config[$type])) {
  909.             $this->cache_config['cached'] = true;
  910.             return true;
  911.         } else {
  912.             if (!$from_bkp) {
  913.                 // Try the current backup
  914.                 @copy($file . '.current', $file);
  915.                 $this->check_cache($type, true);
  916.             }
  917.             $this->cache_config['cached'] = false;
  918.             return false;
  919.         }
  920.     }
  921.  
  922.     /**
  923.      * is_utf8($string)
  924.      * Borrowed from php.net : http://www.php.net/mb_detect_encoding (detectUTF8)
  925.      */
  926.     function is_utf8($string)
  927.     {
  928.         // non-overlong 2-byte|excluding overlongs|straight 3-byte|excluding surrogates|planes 1-3|planes 4-15|plane 16
  929.         return preg_match('%(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF] |\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})+%xs', $string);
  930.     }
  931.  
  932.     /**
  933.      * stripslashes($value)
  934.      * Borrowed from php.net : http://www.php.net/stripslashes
  935.      */
  936.     function stripslashes($value)
  937.     {
  938.         return is_array($value) ? array_map([&$this, 'stripslashes'], $value) : stripslashes($value);
  939.     }
  940.     // --> Add on Functions <--
  941.     // --> Gen stats
  942.     /**
  943.      * Returns usable microtime
  944.      * Borrowed from php.net
  945.      */
  946.     function microtime_float()
  947.     {
  948.         return array_sum(explode(' ', microtime()));
  949.     }
  950. }
Advertisement
Add Comment
Please, Sign In to add comment