示例#1
0
 /**
  * @dataProvider relative_format_date_data()
  */
 public function test_relative_format_date($timestamp, $forcedate, $expected)
 {
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->timezone = new DateTimeZone('UTC');
     $user->lang['datetime'] = array('TODAY' => 'Today', 'TOMORROW' => 'Tomorrow', 'YESTERDAY' => 'Yesterday', 'AGO' => array(0 => 'less than a minute ago', 1 => '%d minute ago', 2 => '%d minutes ago'));
     $timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC'));
     $this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate));
 }
示例#2
0
 public function setUp()
 {
     parent::setUp();
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->add_lang('ucp');
     $request = $this->getMock('\\phpbb\\request\\request');
     $template = $this->getMock('\\phpbb\\template\\template');
     $this->field = new \phpbb\profilefields\type\type_googleplus($request, $template, $user);
 }
示例#3
0
 public function setUp()
 {
     parent::setUp();
     global $phpbb_root_path, $phpEx;
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
     $lang = new \phpbb\language\language($lang_loader);
     $user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $user->add_lang('ucp');
     $request = $this->getMock('\\phpbb\\request\\request');
     $template = $this->getMock('\\phpbb\\template\\template');
     $this->field = new \phpbb\profilefields\type\type_googleplus($request, $template, $user);
 }
示例#4
0
 /**
  * @dataProvider relative_format_date_data()
  */
 public function test_relative_format_date($timestamp, $forcedate, $expected)
 {
     global $phpbb_root_path, $phpEx;
     // This magically fixes the segmentation fault error on PHP7 tests
     // while date_default_timezone_set('UTC') does not
     date_default_timezone_set('Europe/Paris');
     $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
     $lang = new \phpbb\language\language($lang_loader);
     $user = new \phpbb\user($lang, '\\phpbb\\datetime');
     $user->timezone = new DateTimeZone('UTC');
     $user->lang['datetime'] = array('TODAY' => 'Today', 'TOMORROW' => 'Tomorrow', 'YESTERDAY' => 'Yesterday', 'AGO' => array(0 => 'less than a minute ago', 1 => '%d minute ago', 2 => '%d minutes ago'));
     $timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC'));
     $this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate));
 }
示例#5
0
 /**
  * @dataProvider phpbb_exception_data
  */
 public function test_phpbb_exception($is_ajax, $exception, $expected)
 {
     $request = \Symfony\Component\HttpFoundation\Request::create('test.php', 'GET', array(), array(), array(), $is_ajax ? array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') : array());
     $template = $this->getMockBuilder('\\phpbb\\template\\twig\\twig')->disableOriginalConstructor()->getMock();
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->add_lang('common');
     $exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $user);
     $event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
     $exception_listener->on_kernel_exception($event);
     $response = $event->getResponse();
     $this->assertEquals($expected['status_code'], $response->getStatusCode());
     $this->assertEquals($is_ajax, $response instanceof \Symfony\Component\HttpFoundation\JsonResponse);
     if (isset($expected['content'])) {
         $this->assertContains($expected['content'], $response->getContent());
     }
 }
示例#6
0
 public function setUp()
 {
     global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $user, $cache, $auth;
     parent::setUp();
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $db = $this->new_dbal();
     $config = new \phpbb\config\config(array());
     set_config(null, null, null, $config);
     set_config_count(null, null, null, $config);
     $cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), $config, $db, $phpbb_root_path, $phpEx);
     $auth = $this->getMock('\\phpbb\\auth\\auth');
     $auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap(array(array('u_viewprofile', 1, false))));
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->data = array('user_lang' => 'en');
     $user->add_lang('common');
     $user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
     $user_loader->load_users(array(2, 3, 4, 5, 6));
     $this->notification = new phpbb_mock_notification_type_post($user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null, null);
 }
示例#7
0
 public function test_user_lang_sprintf()
 {
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->lang = array('FOO' => 'BAR', 'BARZ' => 'PENG', 'EMPTY' => '', 'ZERO' => '0', 'STR' => '%d %s, %d topics', 'STR2' => '%d foos', 'ARRY' => array(0 => 'No posts', 1 => '1 post', 2 => '%d posts'), 'ARRY_NO_ZERO' => array(1 => '1 post', 2 => '%d posts'), 'ARRY_MISSING' => array(1 => '%d post'), 'ARRY_FLOAT' => array(1 => '1 post', 2 => '%1$.1f posts'), 'ARRY_EMPTY' => array(), 'dateformat' => array('AGO' => array(1 => '%d second', 2 => '%d seconds')));
     // No param
     $this->assertEquals($user->lang('FOO'), 'BAR');
     $this->assertEquals($user->lang('EMPTY'), '');
     $this->assertEquals($user->lang('ZERO'), '0');
     // Invalid index
     $this->assertEquals($user->lang('VOID'), 'VOID');
     // Unnecessary param
     $this->assertEquals($user->lang('FOO', 2), 'BAR');
     $this->assertEquals($user->lang('FOO', 2, 3), 'BAR');
     $this->assertEquals($user->lang('FOO', 2, 3, 'BARZ'), 'BAR');
     // String
     $this->assertEquals($user->lang('STR', 24, 'x', 42), '24 x, 42 topics');
     $this->assertEquals($user->lang('STR2', 64), '64 foos');
     // Array
     $this->assertEquals($user->lang('ARRY', 0), 'No posts');
     $this->assertEquals($user->lang('ARRY', 1), '1 post');
     $this->assertEquals($user->lang('ARRY', 2), '2 posts');
     $this->assertEquals($user->lang('ARRY', 123), '123 posts');
     // Empty array returns the language key
     $this->assertEquals($user->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY');
     // No 0 key defined
     $this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts');
     $this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post');
     $this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts');
     // Array with missing keys
     $this->assertEquals($user->lang('ARRY_MISSING', 2), '2 post');
     // Floats as array key
     $this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post');
     $this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts');
     $this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts');
     // Use sub key, if first paramenter is an array
     $this->assertEquals($user->lang(array('dateformat', 'AGO'), 2), '2 seconds');
     // ticket PHPBB3-9949 - use first int to determinate the plural-form to use
     $this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
     $this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');
     // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+
     $user = new \phpbb\user('\\phpbb\\datetime');
     $user->lang = array('PLURAL_RULE' => 13, 'ARRY' => array(0 => '%d is 0', 1 => '%d is 1', 2 => '%d ends with 01-10', 3 => '%d ends with 11-19', 4 => '%d is part of the last rule'));
     $this->assertEquals($user->lang('ARRY', 0), '0 is 0');
     $this->assertEquals($user->lang('ARRY', 1), '1 is 1');
     $this->assertEquals($user->lang('ARRY', 103), '103 ends with 01-10');
     $this->assertEquals($user->lang('ARRY', 15), '15 ends with 11-19');
     $this->assertEquals($user->lang('ARRY', 300), '300 is part of the last rule');
 }
 public function get_text_formatter_tests()
 {
     return array(array('<t>Plain text</t>', 'Plain text'), array('<r>Hello <URL url="http://example.org"><s>[url=http://example.org]</s>world<e>[/url]</e></URL></r>', 'Hello <a href="http://example.org" class="postlink">world</a>'), array('<t>&amp;&lt;&gt;"\'</t>', '&amp;&lt;&gt;"\''), array('<r><CENSOR with="banana">apple</CENSOR></r>', 'banana', true), array('<r><CENSOR with="banana">apple</CENSOR></r>', 'apple', false), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', 'http://localhost/foo.swf', true, function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewflash', false);
         $phpbb_container->set('user', $user);
     }), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">'), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', true, function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewimg', false);
         $phpbb_container->set('user', $user);
     }), array('<r><E>:)</E></r>', '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" width="15" height="17" alt=":)" title="Smile">'), array('<r><E>:)</E></r>', ':)', true, function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('smilies', false);
         $phpbb_container->set('user', $user);
     }));
 }
示例#9
0
/**
* Stk add lang
*
* A wrapper for the $user->add_lang method that will use the custom language path that is used
* in this tool kit.
* The function shall first try to include the file in the users language, if that fails it will
* take the boards default language, if that also fails it will fall back to English
*
* @param	String	$lang_file	the name of the language file
* @param	mixed	$force_lang	If this parameter contains an ISO code this language
*								is used for the file. If set to "false" the users default
*								langauge will be used
*/
function stk_add_lang($lang_file)
{
    global $config, $user;
    if (!isset($user)) {
        if (file_exists(STK_ROOT_PATH . 'default_lang.txt')) {
            $default_lang = trim(file_get_contents(STK_ROOT_PATH . 'default_lang.txt'));
            if (empty($default_lang)) {
                $default_lang = 'en';
            }
        } else {
            $default_lang = 'en';
        }
        if (!class_exists('phpbb\\session')) {
            include PHPBB_ROOT_PATH . 'phpbb/session.' . PHP_EXT;
        }
        if (!class_exists('phpbb\\user')) {
            include PHPBB_ROOT_PATH . 'phpbb/user.' . PHP_EXT;
        }
        $dir = @opendir(PHPBB_ROOT_PATH . 'language');
        if (!$dir) {
            die('Unable to access the language directory');
            exit;
        }
        while (($file = readdir($dir)) !== false) {
            $path = STK_ROOT_PATH . 'language/' . $file;
            if (!is_file($path) && !is_link($path) && $file == strtolower($default_lang)) {
                $language = $file;
                break;
            }
        }
        closedir($dir);
        if (!file_exists(PHPBB_ROOT_PATH . 'language/' . $language) || !is_dir(PHPBB_ROOT_PATH . 'language/' . $language)) {
            die('No language found!');
        }
        $user = new \phpbb\user('\\phpbb\\datetime');
        $user->lang_path = $user->lang_path . $language;
        $user->data['user_lang'] = $default_lang;
    }
    // Internally cache some data
    static $lang_data = array();
    static $lang_dirs = array();
    // Store current phpBB data
    if (empty($lang_data)) {
        $lang_data = array('lang_path' => $user->lang_path, 'lang_name' => $user->data['user_lang']);
    }
    if (empty($user->lang_path)) {
        die('No language found!');
    }
    // Empty the lang_name
    $user->lang_name = '';
    // Find out what languages we could use
    if (empty($config['default_lang'])) {
        $config['default_lang'] = $language;
    }
    if (empty($lang_dirs)) {
        $lang_dirs = array($user->data['user_lang'], basename($config['default_lang']), 'en');
        // Only unique dirs
        $lang_dirs = array_unique($lang_dirs);
    }
    // Switch to the STK language dir
    $user->lang_path = STK_ROOT_PATH . 'language/';
    // Test all languages
    foreach ($lang_dirs as $dir) {
        if (file_exists($user->lang_path . $dir . "/{$lang_file}." . PHP_EXT)) {
            $user->lang_name = $dir;
            break;
        }
    }
    // No language file :/
    if (empty($user->lang_name)) {
        trigger_error("Language file: {$lang_file}." . PHP_EXT . ' missing!', E_USER_ERROR);
    }
    // Add the file
    $user->add_lang($lang_file);
    // Now reset the paths so phpBB can continue to operate as usual
    $user->lang_path = PHPBB_ROOT_PATH . 'language/';
    $user->lang_name = !isset($user->lang_name) ? $user->lang_name : $user->data['user_lang'];
}
示例#10
0
 function user_setup($user = false)
 {
     if (!isset($user)) {
         if (!class_exists('phpbb\\session')) {
             include PHPBB_ROOT_PATH . 'phpbb/session.' . PHP_EXT;
         }
         if (!class_exists('phpbb\\user')) {
             include PHPBB_ROOT_PATH . 'phpbb/user.' . PHP_EXT;
         }
         if (file_exists(STK_ROOT_PATH . 'default_lang.txt')) {
             $default_lang = trim(file_get_contents(STK_ROOT_PATH . 'default_lang.txt'));
         } else {
             $default_lang = 'en';
         }
         $dir = @opendir(PHPBB_ROOT_PATH . 'language');
         if (!$dir) {
             die('Unable to access the language directory');
             exit;
         }
         while (($file = readdir($dir)) !== false) {
             $path = STK_ROOT_PATH . 'language/' . $file;
             $lang[] = $file;
         }
         closedir($dir);
         $lang = array_diff($lang, array('index.htm', '.', '..'));
         foreach ($lang as $key => $value) {
             if ($value == strtolower($default_lang)) {
                 $language = $value;
             }
         }
         if (empty($language)) {
             $language = $default_lang;
         }
         if (empty($lang)) {
             die('No language found!');
         }
         $user = new \phpbb\user('\\phpbb\\datetime');
         $lang_path = $user->lang_path;
         $lang_path = '' . $lang_path . '' . $language . '';
         $user->lang_path = '' . PHPBB_ROOT_PATH . '' . $lang_path . '';
         $user->data['user_lang'] = $language;
         $user->add_lang(array(), array(), 'install.' . PHP_EXT . '');
         $user->add_lang(array(), array(), 'common.' . PHP_EXT . '');
         $user->lang_path = $lang_path;
     }
     return $user;
 }
示例#11
0
 public function get_default_options_cases()
 {
     return array(array('<t>apple</t>', 'banana'), array('<t>apple</t>', 'banana', function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewcensors', false);
         $phpbb_container->set('user', $user);
     }), array('<t>apple</t>', 'banana', function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewcensors', false);
         $config = new \phpbb\config\config(array('allow_nocensors' => true));
         $phpbb_container->set('user', $user);
         $phpbb_container->set('config', $config);
     }), array('<t>apple</t>', 'apple', function ($phpbb_container, $test) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewcensors', false);
         $config = new \phpbb\config\config(array('allow_nocensors' => true));
         $auth = $test->getMock('phpbb\\auth\\auth');
         $auth->expects($test->any())->method('acl_get')->with('u_chgcensors')->will($test->returnValue(true));
         $phpbb_container->set('user', $user);
         $phpbb_container->set('config', $config);
         $phpbb_container->set('auth', $auth);
     }), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="123" height="456"><param name="movie" value="http://localhost/foo.swf"><param name="play" value="false"><param name="loop" value="false"><param name="quality" value="high"><param name="allowScriptAccess" value="never"><param name="allowNetworking" value="internal"><embed src="http://localhost/foo.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="123" height="456" play="false" loop="false" quality="high" allowscriptaccess="never" allownetworking="internal"></object>'), array('<r><FLASH url="http://localhost/foo.swf" width="123" height="456"><s>[flash=123,456]</s>http://localhost/foo.swf<e>[/flash]</e></FLASH></r>', 'http://localhost/foo.swf', function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewflash', false);
         $phpbb_container->set('user', $user);
     }), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<img src="http://localhost/mrgreen.gif" class="postimage" alt="Image">'), array('<r><IMG src="http://localhost/mrgreen.gif"><s>[img]</s><URL url="http://localhost/mrgreen.gif">http://localhost/mrgreen.gif</URL><e>[/img]</e></IMG></r>', '<a href="http://localhost/mrgreen.gif" class="postlink">http://localhost/mrgreen.gif</a>', function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewimg', false);
         $phpbb_container->set('user', $user);
     }), array('<r><E>:)</E></r>', '<img class="smilies" src="phpBB/images/smilies/icon_e_smile.gif" alt=":)" title="Smile">'), array('<r><E>:)</E></r>', ':)', function ($phpbb_container) {
         global $phpbb_root_path, $phpEx;
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('smilies', false);
         $phpbb_container->set('user', $user);
     }));
 }
示例#12
0
    /**
     * Run the tool
     */
    function run_tool()
    {
        global $cache, $config, $db, $user;
        // Prevent some errors from missing language strings.
        $user->add_lang('posting');
        // Define some vars that we'll need
        $last_batch = false;
        $reparse_id = request_var('reparseids', '');
        $reparse_pm_id = request_var('reparsepms', '');
        $reparse_forum_ids = request_var('reparseforums', array(0));
        $create_backup = request_var('create_backup', false);
        $all = request_var('reparseall', false);
        $mode = request_var('mode', BBCODE_REPARSE_POSTS);
        $step = request_var('step', 0);
        $start = $step * $this->step_size;
        $cnt = 0;
        if (sizeof($reparse_forum_ids)) {
            $reparse_id = '';
            $sql_forum_where = ' WHERE ' . $db->sql_in_set('forum_id', $reparse_forum_ids);
        }
        if (!sizeof($reparse_forum_ids) && !$reparse_id && !$reparse_pm_id && !$all && $step == 0) {
            trigger_error('REPARSE_IDS_EMPTY', E_USER_WARNING);
        }
        // If post IDs or PM IDs were specified, we need to make sure the list is valid.
        $reparse_posts = array();
        $reparse_pms = array();
        if (!empty($reparse_id)) {
            $reparse_posts = explode(',', $reparse_id);
            $reparse_forum_ids = array();
            if (!sizeof($reparse_posts)) {
                trigger_error('REPARSE_IDS_INVALID', E_USER_WARNING);
            }
            // Make sure there's no extra whitespace
            array_walk($reparse_posts, array($this, '_trim_post_ids'));
            $cache->put('_stk_reparse_posts', $reparse_posts);
        } else {
            if ($mode == BBCODE_REPARSE_POSTS) {
                if (($result = $cache->get('_stk_reparse_posts')) !== false) {
                    $reparse_posts = $result;
                }
            }
        }
        if (!empty($reparse_pm_id)) {
            $reparse_pms = explode(',', $reparse_pm_id);
            if (!sizeof($reparse_pms)) {
                trigger_error('REPARSE_IDS_INVALID');
            }
            if (!$all) {
                $mode = BBCODE_REPARSE_PMS;
            }
            // Again, make sure the format is okay
            array_walk($reparse_pms, array($this, '_trim_post_ids'));
            $cache->put('_stk_reparse_pms', $reparse_pms);
        } else {
            if ($mode == BBCODE_REPARSE_PMS) {
                if (($result = $cache->get('_stk_reparse_pms')) !== false) {
                    $reparse_pms = $result;
                }
            }
        }
        // The message parser
        if (!class_exists('parse_message')) {
            global $phpbb_root_path, $phpEx;
            // required!
            include PHPBB_ROOT_PATH . 'includes/message_parser.' . PHP_EXT;
        }
        // Posting helper functions
        if ($mode == BBCODE_REPARSE_POSTS && !function_exists('submit_post')) {
            include PHPBB_ROOT_PATH . 'includes/functions_posting.' . PHP_EXT;
        }
        // PM helper function
        if ($mode == BBCODE_REPARSE_PMS && !function_exists('submit_pm')) {
            include PHPBB_ROOT_PATH . 'includes/functions_privmsgs.' . PHP_EXT;
        }
        // First step? Prepare the backup
        if ($create_backup && $step == 0 && $mode == BBCODE_REPARSE_POSTS) {
            $this->_prepare_backup();
        }
        // Greb our batch
        $bitfield = $all ? true : false;
        // The MSSQL DBMS doesn't break correctly out of the loop
        // when it is finished reparsing the last post. Therefore
        // we'll have to find out manually whether the tool is
        // finished, and if not how many objects it can select
        // if ($this->step_size * $step > 'maxrows')
        // #62822
        // First the easiest, the user selected certain posts/pms
        if (!empty($reparse_posts) || !empty($reparse_pms)) {
            $this->step_size = !empty($reparse_posts) ? sizeof($reparse_posts) : sizeof($reparse_pms);
            // This is always done in one go
            $last_batch = true;
        } else {
            // Get the total
            $this->max = request_var('rowsmax', 0);
            if ($this->max == 0) {
                switch ($mode) {
                    case BBCODE_REPARSE_POSTS:
                        $ccol = 'post_id';
                        $ctab = POSTS_TABLE;
                        $bbf = 'bbcode_bitfield';
                        break;
                    case BBCODE_REPARSE_PMS:
                        $ccol = 'msg_id';
                        $ctab = PRIVMSGS_TABLE;
                        $bbf = 'bbcode_bitfield';
                        break;
                    case BBCODE_REPARSE_SIGS:
                        $ccol = 'user_id';
                        $ctab = USERS_TABLE;
                        $bbf = 'user_sig_bbcode_bitfield';
                        break;
                }
                $sql_where = $bitfield === false ? '' : "WHERE {$bbf} <> ''";
                $sql = "SELECT COUNT({$ccol}) AS cnt\n\t\t\t\t\tFROM {$ctab}\n\t\t\t\t\t{$sql_where}{$sql_forum_where}";
                $result = $db->sql_query($sql);
                $this->max = $db->sql_fetchfield('cnt', false, $result);
                $db->sql_freeresult($result);
            }
            // Change step_size if needed
            if ($start + $this->step_size > $this->max) {
                $this->step_size = $this->max - $start;
                // Make sure that the loop is finished
                $last_batch = true;
                if (!$reparse_id) {
                    // Done!
                    $cache->destroy('_stk_reparse_posts');
                    $cache->destroy('_stk_reparse_pms');
                    trigger_error($user->lang['REPARSE_BBCODE_COMPLETE']);
                }
            }
        }
        switch ($mode) {
            case BBCODE_REPARSE_POSTS:
                if (sizeof($reparse_forum_ids)) {
                    $sql_where = ' AND ' . $db->sql_in_set('f.forum_id', $reparse_forum_ids);
                } else {
                    if (sizeof($reparse_posts)) {
                        $sql_where = ' AND ' . $db->sql_in_set('p.post_id', $reparse_posts);
                    } else {
                        $sql_where = '';
                    }
                }
                $sql_ary = array('SELECT' => 'f.forum_id, f.enable_indexing, f.forum_name,
									p.post_id, p.poster_id, p.icon_id, p.post_text, p.post_subject, p.post_username, p.post_time, p.post_edit_reason, p.bbcode_uid, p. bbcode_bitfield, p.post_checksum, p.enable_sig, p.post_edit_locked, p.enable_bbcode, p.enable_magic_url, p.enable_smilies, p.post_attachment, p.post_edit_user,
									t.topic_id, t.topic_first_post_id, t.topic_last_post_id, t.topic_type, t.topic_status, t.topic_title, t.poll_title, t.topic_time_limit, t.poll_start, t.poll_length, t.poll_max_options, t.poll_last_vote, t.poll_vote_change, t.topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted,
									u.username', 'FROM' => array(FORUMS_TABLE => 'f', POSTS_TABLE => 'p', TOPICS_TABLE => 't', USERS_TABLE => 'u'), 'WHERE' => ($bitfield ? "p.bbcode_bitfield <> '' AND " : '') . 't.topic_id = p.topic_id AND u.user_id = p.poster_id AND f.forum_id = t.forum_id' . $sql_where . '');
                break;
            case BBCODE_REPARSE_PMS:
                $sql_ary = array('SELECT' => 'pm.*, u.username AS author_name', 'FROM' => array(PRIVMSGS_TABLE => 'pm', USERS_TABLE => 'u'), 'WHERE' => ($bitfield ? "pm.bbcode_bitfield <> '' AND " : '') . 'u.user_id = pm.author_id' . (sizeof($reparse_pms) ? ' AND ' . $db->sql_in_set('pm.msg_id', $reparse_pms) : ''));
                break;
            case BBCODE_REPARSE_SIGS:
                $sql_ary = array('SELECT' => 'u.*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => $bitfield ? "u.user_sig_bbcode_bitfield <> ''" : '');
                break;
        }
        $sql = $db->sql_build_query('SELECT', $sql_ary);
        $result = $db->sql_query_limit($sql, $this->step_size, $start);
        $batch = $db->sql_fetchrowset($result);
        $db->sql_freeresult($result);
        // Backup
        if ($create_backup && $mode == BBCODE_REPARSE_POSTS) {
            $this->_backup($batch);
        }
        // User object used to store a second user object used when parsing signatures. (#62451)
        $_user2 = new \phpbb\user('');
        // Walk through the batch
        foreach ($batch as $this->data) {
            // The flags for signatures are hidden inside the user options.
            if ($mode == BBCODE_REPARSE_SIGS) {
                // Set the options
                $this->data['enable_bbcode'] = $_user2->optionget('sig_bbcode', $this->data['user_options']);
                $this->data['enable_magic_url'] = $_user2->optionget('sig_links', $this->data['user_options']);
                $this->data['enable_smilies'] = $_user2->optionget('sig_smilies', $this->data['user_options']);
            }
            // Update the post flags
            $this->flags['enable_bbcode'] = $config['allow_bbcode'] ? $this->data['enable_bbcode'] : false;
            $this->flags['enable_magic_url'] = $config['allow_post_links'] ? $this->data['enable_magic_url'] : false;
            $this->flags['enable_smilies'] = $this->data['enable_smilies'] ? true : false;
            $this->flags['img_status'] = $config['allow_bbcode'] ? true : false;
            $this->flags['flash_status'] = $config['allow_bbcode'] && $config['allow_post_flash'] ? true : false;
            $this->flags['enable_urls'] = $config['allow_post_links'] ? true : false;
            // Reparse them!
            $pm_data = $post_data = $sig_data = array();
            switch ($mode) {
                case BBCODE_REPARSE_POSTS:
                    // Setup the parser
                    $this->message_parser = new parse_message($this->data['post_text']);
                    unset($this->data['post_text']);
                    // Reparse the post
                    $this->_reparse_post($post_data);
                    // Set post_username
                    // post_username is either empty or contains guest username.
                    // If empty post username and if p.poster_id is not ANONYMOUS, use u.username else leave as it is.
                    // Bug #62889
                    $username = '';
                    if ($this->data['poster_id'] == ANONYMOUS) {
                        $username = !empty($this->data['post_username']) ? trim($this->data['post_username']) : '';
                    } else {
                        $username = $this->data['username'];
                    }
                    // Re-submit the post through API
                    submit_post('edit', $this->data['post_subject'], $username, $this->data['topic_type'], $this->poll, $post_data, true, true);
                    break;
                case BBCODE_REPARSE_PMS:
                    // Setup the parser
                    $this->message_parser = new parse_message($this->data['message_text']);
                    unset($this->data['post_text']);
                    // Reparse the pm
                    $this->_reparse_pm($pm_data);
                    // Re-submit the pm through the API
                    submit_pm('edit', $this->data['message_subject'], $pm_data, false);
                    break;
                case BBCODE_REPARSE_SIGS:
                    // SEtup the parser
                    $this->message_parser = new parse_message($this->data['user_sig']);
                    unset($this->data['user_sig']);
                    // Reparse the sig
                    $this->_reparse_sig($sig_data);
                    // Insert back into the db
                    $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sig_data) . '
						WHERE user_id = ' . (int) $this->data['user_id'];
                    $db->sql_query($sql);
                    break;
            }
            // Unset some vars so the next round starts clean
            $this->message_parser = null;
            $this->poll_parser = null;
            unset($this->poll, $post_data, $pm_data);
            $this->flags = array_fill_keys(array_keys($this->flags), false);
            $_user2->keyvalues = array();
        }
        // Finished?
        if ($last_batch && ($mode == BBCODE_REPARSE_SIGS || !$all)) {
            // Done!
            $cache->destroy('_stk_reparse_posts');
            $cache->destroy('_stk_reparse_pms');
            trigger_error($user->lang['REPARSE_BBCODE_COMPLETE']);
        } else {
            if ($last_batch) {
                // Move to the next type
                $this->_next_step(0, $mode, true);
            }
        }
        // Next step
        $this->_next_step($step, $mode);
    }
示例#13
0
	public function test_lang_plural_rules_bc()
	{
		$user = new \phpbb\user($this->lang, '\phpbb\datetime');

		// ticket PHPBB3-10345 - different plural rules, not just 0/1/2+
		$this->assertEquals($user->lang('PLURAL_ARRY', 0), '0 is 0');
		$this->assertEquals($user->lang('PLURAL_ARRY', 1), '1 is 1');
		$this->assertEquals($user->lang('PLURAL_ARRY', 103), '103 ends with 01-10');
		$this->assertEquals($user->lang('PLURAL_ARRY', 15), '15 ends with 11-19');
		$this->assertEquals($user->lang('PLURAL_ARRY', 300), '300 is part of the last rule');
	}
示例#14
0
 /**
  * Set working instances of the text_formatter.* services
  *
  * If no container is passed, the global $phpbb_container will be used and/or
  * created if applicable
  *
  * @param  ContainerInterface $container   Service container
  * @param  string             $fixture     Path to the XML fixture
  * @param  string             $styles_path Path to the styles dir
  * @return ContainerInterface
  */
 public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null)
 {
     static $first_run;
     global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
     $cache_dir = __DIR__ . '/../tmp/';
     // Remove old cache files on first run
     if (!isset($first_run)) {
         $first_run = 1;
         array_map('unlink', array_merge(glob($cache_dir . 'data_s9e_*'), glob($cache_dir . 's9e_*')));
     }
     if (!isset($container)) {
         if (!isset($phpbb_container)) {
             $phpbb_container = new phpbb_mock_container_builder();
         }
         $container = $phpbb_container;
     }
     if (!isset($fixture)) {
         $fixture = __DIR__ . '/../text_formatter/s9e/fixtures/default_formatting.xml';
     }
     if (!isset($styles_path)) {
         $styles_path = $phpbb_root_path . 'styles/';
     }
     $dataset = new DOMDocument();
     $dataset->load($fixture);
     $tables = array('phpbb_bbcodes' => array(), 'phpbb_smilies' => array(), 'phpbb_styles' => array(), 'phpbb_words' => array());
     foreach ($dataset->getElementsByTagName('table') as $table) {
         $name = $table->getAttribute('name');
         $columns = array();
         foreach ($table->getElementsByTagName('column') as $column) {
             $columns[] = $column->textContent;
         }
         foreach ($table->getElementsByTagName('row') as $row) {
             $values = array();
             foreach ($row->getElementsByTagName('value') as $value) {
                 $values[] = $value->textContent;
             }
             $tables[$name][] = array_combine($columns, $values);
         }
     }
     // Set up a default style if there's none set
     if (empty($tables['phpbb_styles'])) {
         $tables['phpbb_styles'][] = array('style_id' => 1, 'style_path' => 'prosilver', 'bbcode_bitfield' => 'kNg=');
     }
     // Mock the DAL, make it return data from the fixture
     $mb = $this->test_case->getMockBuilder('phpbb\\textformatter\\data_access');
     $mb->setMethods(array('get_bbcodes', 'get_censored_words', 'get_smilies', 'get_styles'));
     $mb->setConstructorArgs(array($this->test_case->getMock('phpbb\\db\\driver\\driver'), 'phpbb_bbcodes', 'phpbb_smilies', 'phpbb_styles', 'phpbb_words', $styles_path));
     $dal = $mb->getMock();
     $container->set('text_formatter.data_access', $dal);
     $dal->expects($this->test_case->any())->method('get_bbcodes')->will($this->test_case->returnValue($tables['phpbb_bbcodes']));
     $dal->expects($this->test_case->any())->method('get_smilies')->will($this->test_case->returnValue($tables['phpbb_smilies']));
     $dal->expects($this->test_case->any())->method('get_styles')->will($this->test_case->returnValue($tables['phpbb_styles']));
     $dal->expects($this->test_case->any())->method('get_censored_words')->will($this->test_case->returnValue($tables['phpbb_words']));
     // Cache the parser and renderer with a key based on this method's arguments
     $cache = new \phpbb\cache\driver\file($cache_dir);
     $prefix = '_s9e_' . md5(serialize(func_get_args()));
     $cache_key_parser = $prefix . '_parser';
     $cache_key_renderer = $prefix . '_renderer';
     $container->set('cache.driver', $cache);
     $container->setParameter('cache.dir', $cache_dir);
     // Create a path_helper
     if (!$container->has('path_helper')) {
         $container->set('path_helper', new \phpbb\path_helper(new \phpbb\symfony_request(new phpbb_mock_request()), new \phpbb\filesystem(), $this->test_case->getMock('\\phpbb\\request\\request'), $phpbb_root_path, $phpEx));
     }
     // Create an event dispatcher
     if ($container->has('dispatcher')) {
         $dispatcher = $container->get('dispatcher');
     } else {
         if (isset($phpbb_dispatcher)) {
             $dispatcher = $phpbb_dispatcher;
         } else {
             $dispatcher = new phpbb_mock_event_dispatcher();
         }
     }
     if (!isset($phpbb_dispatcher)) {
         $phpbb_dispatcher = $dispatcher;
     }
     // Create and register the text_formatter.s9e.factory service
     $factory = new \phpbb\textformatter\s9e\factory($dal, $cache, $dispatcher, $cache_dir, $cache_key_parser, $cache_key_renderer);
     $container->set('text_formatter.s9e.factory', $factory);
     // Create a user if none was provided, and add the common lang strings
     if ($container->has('user')) {
         $user = $container->get('user');
     } else {
         $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
         $lang = new \phpbb\language\language($lang_loader);
         $user = new \phpbb\user($lang, '\\phpbb\\datetime');
         $user->optionset('viewcensors', true);
         $user->optionset('viewflash', true);
         $user->optionset('viewimg', true);
         $user->optionset('viewsmilies', true);
         $container->set('user', $user);
     }
     $user->add_lang('common');
     if (!isset($user->style)) {
         $user->style = array('style_id' => 1);
     }
     // Create and register the text_formatter.s9e.parser service and its alias
     $parser = new \phpbb\textformatter\s9e\parser($cache, $cache_key_parser, $factory, $dispatcher);
     $container->set('text_formatter.parser', $parser);
     $container->set('text_formatter.s9e.parser', $parser);
     // Create and register the text_formatter.s9e.renderer service and its alias
     $renderer = new \phpbb\textformatter\s9e\renderer($cache, $cache_dir, $cache_key_renderer, $factory, $dispatcher);
     $config = $container->has('config') ? $container->get('config') : new \phpbb\config\config(array('smilies_path' => 'images/smilies', 'allow_nocensors' => false));
     $auth = $container->has('auth') ? $container->get('auth') : new \phpbb\auth\auth();
     // Calls configured in services.yml
     $renderer->configure_smilies_path($config, $container->get('path_helper'));
     $renderer->configure_user($user, $config, $auth);
     $container->set('text_formatter.renderer', $renderer);
     $container->set('text_formatter.s9e.renderer', $renderer);
     // Create and register the text_formatter.s9e.utils service and its alias
     $utils = new \phpbb\textformatter\s9e\utils();
     $container->set('text_formatter.utils', $utils);
     $container->set('text_formatter.s9e.utils', $utils);
     return $container;
 }