Example #1
0
 /**
  * Parse BBCode
  */
 function parse_bbcode()
 {
     if (!$this->bbcodes) {
         $this->bbcode_init();
     }
     global $user;
     $this->bbcode_bitfield = '';
     $bitfield = new bitfield();
     foreach ($this->bbcodes as $bbcode_name => $bbcode_data) {
         if (isset($bbcode_data['disabled']) && $bbcode_data['disabled']) {
             foreach ($bbcode_data['regexp'] as $regexp => $replacement) {
                 if (preg_match($regexp, $this->message)) {
                     $this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'], '[' . $bbcode_name . ']');
                     continue;
                 }
             }
         } else {
             foreach ($bbcode_data['regexp'] as $regexp => $replacement) {
                 // The pattern gets compiled and cached by the PCRE extension,
                 // it should not demand recompilation
                 if (preg_match($regexp, $this->message)) {
                     $this->message = preg_replace($regexp, $replacement, $this->message);
                     $bitfield->set($bbcode_data['bbcode_id']);
                 }
             }
         }
     }
     $this->bbcode_bitfield = $bitfield->get_base64();
 }
Example #2
0
 /**
  * Return the bbcode.html template for every installed style
  *
  * @return array 2D array. style_id as keys, each element is an array with a "template" element that contains the style's bbcode.html and a "bbcodes" element that contains the name of each BBCode that is to be stylised
  */
 public function get_styles_templates()
 {
     $templates = array();
     $bbcode_ids = array('quote' => 0, 'b' => 1, 'i' => 2, 'url' => 3, 'img' => 4, 'size' => 5, 'color' => 6, 'u' => 7, 'code' => 8, 'list' => 9, '*' => 9, 'email' => 10, 'flash' => 11, 'attachment' => 12);
     $styles = array();
     foreach ($this->get_styles() as $row) {
         $styles[$row['style_id']] = $row;
     }
     foreach ($styles as $style_id => $style) {
         $bbcodes = array();
         // Collect the name of the BBCodes whose bit is set in the style's bbcode_bitfield
         $template_bitfield = new \bitfield($style['bbcode_bitfield']);
         foreach ($bbcode_ids as $bbcode_name => $bit) {
             if ($template_bitfield->get($bit)) {
                 $bbcodes[] = $bbcode_name;
             }
         }
         $filename = $this->resolve_style_filename($styles, $style);
         if ($filename === false) {
             // Ignore this style, it will use the default templates
             continue;
         }
         $templates[$style_id] = array('bbcodes' => $bbcodes, 'template' => file_get_contents($filename));
     }
     return $templates;
 }
Example #3
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache;
        global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        // Hardcoded template bitfield to add for new templates
        $bitfield = new bitfield();
        $bitfield->set(0);
        $bitfield->set(1);
        $bitfield->set(2);
        $bitfield->set(3);
        $bitfield->set(4);
        $bitfield->set(8);
        $bitfield->set(9);
        $bitfield->set(11);
        $bitfield->set(12);
        define('TEMPLATE_BITFIELD', $bitfield->get_base64());
        unset($bitfield);
        $user->add_lang('acp/styles');
        $this->tpl_name = 'acp_styles';
        $this->page_title = 'ACP_CAT_STYLES';
        $action = request_var('action', '');
        $action = isset($_POST['add']) ? 'add' : $action;
        $style_id = request_var('id', 0);
        // Fill the configuration variables
        $this->style_cfg = $this->template_cfg = $this->theme_cfg = $this->imageset_cfg = '
#
# phpBB {MODE} configuration file
#
# @package phpBB3
# @copyright (c) 2005 phpBB Group
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
#
#
# At the left is the name, please do not change this
# At the right the value is entered
# For on/off options the valid values are on, off, 1, 0, true and false
#
# Values get trimmed, if you want to add a space in front or at the end of
# the value, then enclose the value with single or double quotes.
# Single and double quotes do not need to be escaped.
#
#

# General Information about this {MODE}
name = {NAME}
copyright = {COPYRIGHT}
version = {VERSION}
';
        $this->theme_cfg .= '
# Some configuration options

#
# You have to turn this option on if you want to use the
# path template variables ({T_IMAGESET_PATH} for example) within
# your css file.
# This is mostly the case if you want to use language specific
# images within your css file.
#
parse_css_file = {PARSE_CSS_FILE}
';
        $this->template_cfg .= '
# Some configuration options

#
# You can use this function to inherit templates from another template.
# The template of the given name has to be installed.
# Templates cannot inherit from inheriting templates.
#';
        $this->imageset_keys = array('logos' => array('site_logo'), 'buttons' => array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_quickedit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply', 'icon_topic_solved_set', 'icon_topic_solved_unset', 'icon_topic_solved_head', 'icon_topic_solved_list', 'icon_topic_solved_post'), 'icons' => array('icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe'), 'forums' => array('forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'), 'folders' => array('topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread'), 'polls' => array('poll_left', 'poll_center', 'poll_right'), 'ui' => array('upload_bar'), 'user' => array('user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10'));
        // [+] Karma MOD
        global $karmamod;
        $karmamod->acp_styles_imageset($this->imageset_keys);
        // [-] Karma MOD
        // Execute overall actions
        switch ($action) {
            case 'delete':
                if ($style_id) {
                    $this->remove($mode, $style_id);
                    return;
                }
                break;
            case 'export':
                if ($style_id) {
                    $this->export($mode, $style_id);
                    return;
                }
                break;
            case 'install':
                $this->install($mode);
                return;
                break;
            case 'add':
                $this->add($mode);
                return;
                break;
            case 'details':
                if ($style_id) {
                    $this->details($mode, $style_id);
                    return;
                }
                break;
            case 'edit':
                if ($style_id) {
                    switch ($mode) {
                        case 'imageset':
                            return $this->edit_imageset($style_id);
                        case 'template':
                            return $this->edit_template($style_id);
                        case 'theme':
                            return $this->edit_theme($style_id);
                    }
                }
                break;
            case 'cache':
                if ($style_id) {
                    switch ($mode) {
                        case 'template':
                            return $this->template_cache($style_id);
                    }
                }
                break;
        }
        switch ($mode) {
            case 'style':
                switch ($action) {
                    case 'activate':
                    case 'deactivate':
                        if ($style_id == $config['default_style']) {
                            trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        if ($action == 'deactivate' && confirm_box(true) || $action == 'activate') {
                            $sql = 'UPDATE ' . STYLES_TABLE . '
								SET style_active = ' . ($action == 'activate' ? 1 : 0) . '
								WHERE style_id = ' . $style_id;
                            $db->sql_query($sql);
                            // Set style to default for any member using deactivated style
                            if ($action == 'deactivate') {
                                $sql = 'UPDATE ' . USERS_TABLE . '
									SET user_style = ' . $config['default_style'] . "\n\t\t\t\t\t\t\t\t\tWHERE user_style = {$style_id}";
                                $db->sql_query($sql);
                                $sql = 'UPDATE ' . FORUMS_TABLE . '
									SET forum_style = 0
									WHERE forum_style = ' . $style_id;
                                $db->sql_query($sql);
                            }
                        } else {
                            if ($action == 'deactivate') {
                                $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'action' => $action, 'style_id' => $style_id);
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
                            }
                        }
                        break;
                }
                $this->frontend('style', array('details'), array('export', 'delete'));
                break;
            case 'template':
                switch ($action) {
                    // Refresh template data stored in db and clear cache
                    case 'refresh':
                        $sql = 'SELECT *
							FROM ' . STYLES_TEMPLATE_TABLE . "\n\t\t\t\t\t\t\tWHERE template_id = {$style_id}";
                        $result = $db->sql_query($sql);
                        $template_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$template_row) {
                            trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        if (confirm_box(true)) {
                            $template_refreshed = '';
                            // Only refresh database if the template is stored in the database
                            if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) {
                                $filelist = array('' => array());
                                $sql = 'SELECT template_filename, template_mtime
									FROM ' . STYLES_TEMPLATE_DATA_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE template_id = {$style_id}";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    //									if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime'])
                                    //									{
                                    // get folder info from the filename
                                    if (($slash_pos = strrpos($row['template_filename'], '/')) === false) {
                                        $filelist[''][] = $row['template_filename'];
                                    } else {
                                        $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1);
                                    }
                                    //									}
                                }
                                $db->sql_freeresult($result);
                                $this->store_templates('update', $style_id, $template_row['template_path'], $filelist);
                                unset($filelist);
                                $template_refreshed = $user->lang['TEMPLATE_REFRESHED'] . '<br />';
                                add_log('admin', 'LOG_TEMPLATE_REFRESHED', $template_row['template_name']);
                            }
                            $this->clear_template_cache($template_row);
                            trigger_error($template_refreshed . $user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $template_row['template_storedb'] ? $user->lang['CONFIRM_TEMPLATE_REFRESH'] : $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $style_id)));
                        }
                        break;
                }
                $this->frontend('template', array('edit', 'cache', 'details'), array('refresh', 'export', 'delete'));
                break;
            case 'theme':
                switch ($action) {
                    // Refresh theme data stored in the database
                    case 'refresh':
                        $sql = 'SELECT *
							FROM ' . STYLES_THEME_TABLE . "\n\t\t\t\t\t\t\tWHERE theme_id = {$style_id}";
                        $result = $db->sql_query($sql);
                        $theme_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$theme_row) {
                            trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        if (!$theme_row['theme_storedb']) {
                            trigger_error($user->lang['THEME_ERR_REFRESH_FS'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        if (confirm_box(true)) {
                            if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) {
                                // Save CSS contents
                                $sql_ary = array('theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), 'theme_data' => $this->db_theme_data($theme_row));
                                $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\t\tWHERE theme_id = {$style_id}";
                                $db->sql_query($sql);
                                $cache->destroy('sql', STYLES_THEME_TABLE);
                                add_log('admin', 'LOG_THEME_REFRESHED', $theme_row['theme_name']);
                                trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action));
                            }
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_THEME_REFRESH'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $style_id)));
                        }
                        break;
                }
                $this->frontend('theme', array('edit', 'details'), array('refresh', 'export', 'delete'));
                break;
            case 'imageset':
                switch ($action) {
                    case 'refresh':
                        $sql = 'SELECT *
							FROM ' . STYLES_IMAGESET_TABLE . "\n\t\t\t\t\t\t\tWHERE imageset_id = {$style_id}";
                        $result = $db->sql_query($sql);
                        $imageset_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$imageset_row) {
                            trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        if (confirm_box(true)) {
                            $sql_ary = array();
                            $imageset_definitions = array();
                            foreach ($this->imageset_keys as $topic => $key_array) {
                                $imageset_definitions = array_merge($imageset_definitions, $key_array);
                            }
                            $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg");
                            $db->sql_transaction('begin');
                            $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
								WHERE imageset_id = ' . $style_id;
                            $result = $db->sql_query($sql);
                            foreach ($cfg_data_imageset as $image_name => $value) {
                                if (strpos($value, '*') !== false) {
                                    if (substr($value, -1, 1) === '*') {
                                        list($image_filename, $image_height) = explode('*', $value);
                                        $image_width = 0;
                                    } else {
                                        list($image_filename, $image_height, $image_width) = explode('*', $value);
                                    }
                                } else {
                                    $image_filename = $value;
                                    $image_height = $image_width = 0;
                                }
                                if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                    $image_name = substr($image_name, 4);
                                    if (in_array($image_name, $imageset_definitions)) {
                                        $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $style_id, 'image_lang' => '');
                                    }
                                }
                            }
                            $sql = 'SELECT lang_dir
								FROM ' . LANG_TABLE;
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) {
                                    $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg");
                                    foreach ($cfg_data_imageset_data as $image_name => $value) {
                                        if (strpos($value, '*') !== false) {
                                            if (substr($value, -1, 1) === '*') {
                                                list($image_filename, $image_height) = explode('*', $value);
                                                $image_width = 0;
                                            } else {
                                                list($image_filename, $image_height, $image_width) = explode('*', $value);
                                            }
                                        } else {
                                            $image_filename = $value;
                                            $image_height = $image_width = 0;
                                        }
                                        if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                            $image_name = substr($image_name, 4);
                                            if (in_array($image_name, $imageset_definitions)) {
                                                $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $style_id, 'image_lang' => (string) $row['lang_dir']);
                                            }
                                        }
                                    }
                                }
                            }
                            $db->sql_freeresult($result);
                            $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                            $db->sql_transaction('commit');
                            $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                            add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']);
                            trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_IMAGESET_REFRESH'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $style_id)));
                        }
                        break;
                }
                $this->frontend('imageset', array('edit', 'details'), array('refresh', 'export', 'delete'));
                break;
        }
    }
Example #4
0
    /**
     * Install a style on the demo board.
     *
     * @param string $phpbb_root_path
     * @param mixed contrib object
     */
    public function install_demo_style($phpbb_root_path, $contrib)
    {
        phpbb::$user->add_lang('acp/styles');
        if ($phpbb_root_path[strlen($phpbb_root_path) - 1] != '/') {
            $phpbb_root_path .= '/';
        }
        if (!is_dir($phpbb_root_path) || !file_exists($phpbb_root_path . 'config.' . PHP_EXT)) {
            $this->error[] = 'PATH_INVALID';
            return false;
        }
        include $phpbb_root_path . 'config.' . PHP_EXT;
        $sql_db = !empty($dbms) ? 'dbal_' . basename($dbms) : 'dbal';
        // Is this DBAL loaded?
        phpbb::_include('db/' . $dbms, false, $sql_db);
        // Instantiate DBAL class
        $db = new $sql_db();
        // Connect to demo board DB
        $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
        // We do not need this any longer, unset for safety purposes
        unset($dbpasswd);
        if (empty($this->unzip_dir)) {
            // Extract zip.
            $this->unzip_dir = titania::$config->contrib_temp_path . basename($this->original_zip, 'zip') . '/';
            // Clear out old stuff if there is anything here...
            $this->rmdir_recursive($this->unzip_dir);
            // Unzip to our temp directory
            $this->extract($this->original_zip, $this->unzip_dir);
        }
        $package_root = $this->find_root(false, 'style.cfg');
        $stylecfg = parse_cfg_file($this->unzip_dir . $package_root . '/style.cfg');
        $style_root = $phpbb_root_path . 'styles/' . $contrib->contrib_id . '/';
        $this->mvdir_recursive($this->unzip_dir . $package_root, $style_root, false);
        $this->rmdir_recursive($this->unzip_dir);
        $variables = array('db', 'phpbb_root_path');
        // Let's get lazy.
        foreach ($variables as $variable) {
            ${'_' . $variable} = $GLOBALS[$variable];
            $GLOBALS[$variable] = ${$variable};
        }
        // Get the acp_styles class.
        phpbb::_include('acp/acp_styles', false, 'acp_styles');
        if (!defined('TEMPLATE_BITFIELD')) {
            // Hardcoded template bitfield to add for new templates
            $bitfield = new bitfield();
            $bitfield->set(0);
            $bitfield->set(1);
            $bitfield->set(2);
            $bitfield->set(3);
            $bitfield->set(4);
            $bitfield->set(8);
            $bitfield->set(9);
            $bitfield->set(11);
            $bitfield->set(12);
            define('TEMPLATE_BITFIELD', $bitfield->get_base64());
            unset($bitfield);
        }
        $styles = new acp_styles();
        // Fill the configuration variables
        $styles->style_cfg = $styles->template_cfg = $styles->theme_cfg = $styles->imageset_cfg = '
#
# phpBB {MODE} configuration file
#
# @package phpBB3
# @copyright (c) 2005 phpBB Group
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
#
#
# At the left is the name, please do not change this
# At the right the value is entered
# For on/off options the valid values are on, off, 1, 0, true and false
#
# Values get trimmed, if you want to add a space in front or at the end of
# the value, then enclose the value with single or double quotes.
# Single and double quotes do not need to be escaped.
#
#

# General Information about this {MODE}
name = {NAME}
copyright = {COPYRIGHT}
version = {VERSION}
';
        $styles->theme_cfg .= '
# Some configuration options

#
# You have to turn this option on if you want to use the
# path template variables ({T_IMAGESET_PATH} for example) within
# your css file.
# This is mostly the case if you want to use language specific
# images within your css file.
#
parse_css_file = {PARSE_CSS_FILE}
';
        $styles->template_cfg .= '
# Some configuration options

#
# You can use this function to inherit templates from another template.
# The template of the given name has to be installed.
# Templates cannot inherit from inheriting templates.
#';
        $styles->imageset_keys = array('logos' => array('site_logo'), 'buttons' => array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply'), 'icons' => array('icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe'), 'forums' => array('forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'), 'folders' => array('topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread'), 'polls' => array('poll_left', 'poll_center', 'poll_right'), 'ui' => array('upload_bar'), 'user' => array('user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10'));
        // Define references.
        $error = array();
        $style_id = 0;
        $style_row = array('install_name' => $stylecfg['name'], 'install_copyright' => $stylecfg['copyright'], 'template_id' => 0, 'template_name' => $stylecfg['name'], 'template_copyright' => $stylecfg['copyright'], 'theme_id' => 0, 'theme_name' => $stylecfg['name'], 'theme_copyright' => $stylecfg['copyright'], 'imageset_id' => 0, 'imageset_name' => $stylecfg['name'], 'imageset_copyright' => $stylecfg['copyright'], 'store_db' => 0, 'style_active' => 1, 'style_default' => 0);
        // Install the style.
        // (&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false, $imageset_root_path = false, $imageset_path = false)
        if (!$styles->install_style($error, 'install', $style_root, $style_id, $stylecfg['name'], $contrib->contrib_id, $stylecfg['copyright'], true, false, $style_row)) {
            if ($error != array(phpbb::$user->lang['STYLE_ERR_NAME_EXIST'])) {
                $this->error = array_merge($this->error, $error);
            } else {
                $sql = 'SELECT style_id
					FROM ' . STYLES_TABLE . "\n\t\t\t\t\tWHERE style_name = '" . $db->sql_escape(basename($stylecfg['name'])) . "'";
                $db->sql_query($sql);
                $style_id = $db->sql_fetchfield('style_id');
                $db->sql_freeresult();
            }
        }
        // Have UMIL refresh the template, theme, imageset
        phpbb::_include('../umil/umil', false, 'umil');
        $umil = new umil(true, $db);
        $umil->cache_purge('template', $style_id);
        $umil->cache_purge('theme', $style_id);
        $umil->cache_purge('imageset', $style_id);
        foreach ($variables as $variable) {
            $GLOBALS[$variable] = ${'_' . $variable};
        }
        return $style_id;
    }
function has_flash_enabled($bitfield_data)
{
	$bitfield = new bitfield($bitfield_data);
	return $bitfield->get(11);
}
Example #6
0
    /**
     * Init bbcode cache
     *
     * requires: $this->bbcode_bitfield
     * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
     */
    function bbcode_cache_init()
    {
        global $phpbb_root_path, $template, $user;
        if (empty($this->template_filename)) {
            $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
            $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
            if (!@file_exists($this->template_filename)) {
                if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) {
                    $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/bbcode.html';
                    if (!@file_exists($this->template_filename)) {
                        trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
                    }
                } else {
                    trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
                }
            }
        }
        $bbcode_ids = $rowset = $sql = array();
        $bitfield = new bitfield($this->bbcode_bitfield);
        $bbcodes_set = $bitfield->get_all_set();
        foreach ($bbcodes_set as $bbcode_id) {
            if (isset($this->bbcode_cache[$bbcode_id])) {
                // do not try to re-cache it if it's already in
                continue;
            }
            $bbcode_ids[] = $bbcode_id;
            if ($bbcode_id > NUM_CORE_BBCODES) {
                $sql[] = $bbcode_id;
            }
        }
        if (sizeof($sql)) {
            global $db;
            $sql = 'SELECT *
				FROM ' . BBCODES_TABLE . '
				WHERE ' . $db->sql_in_set('bbcode_id', $sql);
            $result = $db->sql_query($sql, 3600);
            while ($row = $db->sql_fetchrow($result)) {
                // To circumvent replacing newlines with <br /> for the generated html,
                // we use carriage returns here. They are later changed back to newlines
                $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
                $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
                $rowset[$row['bbcode_id']] = $row;
            }
            $db->sql_freeresult($result);
        }
        foreach ($bbcode_ids as $bbcode_id) {
            switch ($bbcode_id) {
                case 0:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)), 'preg' => array('#\\[quote(?:=&quot;(.*?)&quot;)?:$uid\\]((?!\\[quote(?:=&quot;.*?&quot;)?:$uid\\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')"));
                    break;
                case 1:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id), '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id)));
                    break;
                case 2:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id), '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id)));
                    break;
                case 3:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[url:$uid\\]((.*?))\\[/url:$uid\\]#s' => $this->bbcode_tpl('url', $bbcode_id), '#\\[url=([^\\[]+?):$uid\\](.*?)\\[/url:$uid\\]#s' => $this->bbcode_tpl('url', $bbcode_id)));
                    break;
                case 4:
                    if ($user->optionget('viewimg')) {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[img:$uid\\](.*?)\\[/img:$uid\\]#s' => $this->bbcode_tpl('img', $bbcode_id)));
                    } else {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[img:$uid\\](.*?)\\[/img:$uid\\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true))));
                    }
                    break;
                case 5:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[size=([\\-\\+]?\\d+):$uid\\](.*?)\\[/size:$uid\\]#s' => $this->bbcode_tpl('size', $bbcode_id)));
                    break;
                case 6:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('!\\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\\-]+):$uid\\](.*?)\\[/color:$uid\\]!is' => $this->bbcode_tpl('color', $bbcode_id)));
                    break;
                case 7:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id), '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id)));
                    break;
                case 8:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[code(?:=([a-z]+))?:$uid\\](.*?)\\[/code:$uid\\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')"));
                    break;
                case 9:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#(\\[\\/?(list|\\*):[mou]?:?$uid\\])[\\n]{1}#' => "\$1", '#(\\[list=([^\\[]+):$uid\\])[\\n]{1}#' => "\$1", '#\\[list=([^\\[]+):$uid\\]#e' => "\$this->bbcode_list('\$1')"), 'str' => array('[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id), '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id), '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id), '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id), '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id), '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id)));
                    break;
                case 10:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[email:$uid\\]((.*?))\\[/email:$uid\\]#is' => $this->bbcode_tpl('email', $bbcode_id), '#\\[email=([^\\[]+):$uid\\](.*?)\\[/email:$uid\\]#is' => $this->bbcode_tpl('email', $bbcode_id)));
                    break;
                case 11:
                    if ($user->optionget('viewflash')) {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[flash=([0-9]+),([0-9]+):$uid\\](.*?)\\[/flash:$uid\\]#' => $this->bbcode_tpl('flash', $bbcode_id)));
                    } else {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[flash=([0-9]+),([0-9]+):$uid\\](.*?)\\[/flash:$uid\\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))));
                    }
                    break;
                case 12:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)), 'preg' => array('#\\[attachment=([0-9]+):$uid\\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)));
                    break;
                default:
                    if (isset($rowset[$bbcode_id])) {
                        if ($this->template_bitfield->get($bbcode_id)) {
                            // The bbcode requires a custom template to be loaded
                            if (!($bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))) {
                                // For some reason, the required template seems not to be available, use the default template
                                $bbcode_tpl = !empty($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
                            } else {
                                // In order to use templates with custom bbcodes we need
                                // to replace all {VARS} to corresponding backreferences
                                // Note that backreferences are numbered from bbcode_match
                                if (preg_match_all('/\\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\\}/', $rowset[$bbcode_id]['bbcode_match'], $m)) {
                                    foreach ($m[0] as $i => $tok) {
                                        $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
                                    }
                                }
                            }
                        } else {
                            // Default template
                            $bbcode_tpl = !empty($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
                        }
                        // Replace {L_*} lang strings
                        $bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
                        if (!empty($rowset[$bbcode_id]['second_pass_replace'])) {
                            // The custom BBCode requires second-pass pattern replacements
                            $this->bbcode_cache[$bbcode_id] = array('preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl));
                        } else {
                            $this->bbcode_cache[$bbcode_id] = array('str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl));
                        }
                    } else {
                        $this->bbcode_cache[$bbcode_id] = false;
                    }
                    break;
            }
        }
    }
/**
* BBCode-safe truncating of text
*
* From: http://www.phpbb.com/community/viewtopic.php?f=71&t=670335
* Slightly modified to trim at either the first found end line or space
*
* @param string $text Text containing BBCode tags to be truncated
* @param string $uid BBCode uid
* @param int $max_length Text length limit
* @param string $bitfield BBCode bitfield (optional)
* @param bool $enable_bbcode Whether BBCode is enabled (true by default)
* @return string
*/
function trim_text($text, $uid, $max_length, $bitfield = '', $enable_bbcode = true)
{
    // If there is any custom BBCode that can have space in its argument, turn this on,
    // but else I suggest turning this off as it adds one additional (cache) SQL query
    $check_custom_bbcodes = true;
    if ($enable_bbcode && $check_custom_bbcodes) {
        global $db;
        static $custom_bbcodes = array();
        // Get all custom bbcodes
        if (empty($custom_bbcodes)) {
            $sql = 'SELECT bbcode_id, bbcode_tag
			FROM ' . BBCODES_TABLE;
            $result = $db->sql_query($sql, 108000);
            while ($row = $db->sql_fetchrow($result)) {
                // There can be problems only with tags having an argument
                if (substr($row['bbcode_tag'], -1, 1) == '=') {
                    $custom_bbcodes[$row['bbcode_id']] = array('[' . $row['bbcode_tag'], ':' . $uid . ']');
                }
            }
            $db->sql_freeresult($result);
        }
    }
    // First truncate the text
    if (utf8_strlen($text) > $max_length) {
        $next_space = strpos(substr($text, $max_length), ' ');
        $next_el = strpos(substr($text, $max_length), "\n");
        if ($next_space !== false) {
            if ($next_el !== false) {
                $max_length = $next_space < $next_el ? $next_space + $max_length : $next_el + $max_length;
            } else {
                $max_length = $next_space + $max_length;
            }
        } else {
            if ($next_el !== false) {
                $max_length = $next_el + $max_length;
            } else {
                $max_length = utf8_strlen($text);
            }
        }
        $text = utf8_substr($text, 0, $max_length);
        // Append three dots indicating that this is not the real end of the text
        $text .= '...';
        if (!$enable_bbcode) {
            return $text;
        }
    } else {
        return $text;
    }
    // Some tags may contain spaces inside the tags themselves.
    // If there is any tag that had been started but not ended
    // cut the string off before it begins and add three dots
    // to the end of the text again as this has been just cut off too.
    $unsafe_tags = array(array('<', '>'), array('[quote=&quot;', "&quot;:{$uid}]"));
    // If bitfield is given only check for tags that are surely existing in the text
    if (!empty($bitfield)) {
        // Get all used tags
        $bitfield = new bitfield($bitfield);
        $bbcodes_set = $bitfield->get_all_set();
        // Add custom BBCodes having a parameter and being used
        // to the array of potential tags that can be cut apart.
        foreach ($custom_bbcodes as $bbcode_id => $bbcode_name) {
            if (in_array($bbcode_id, $bbcodes_set)) {
                $unsafe_tags[] = $bbcode_name;
            }
        }
    } else {
        $unsafe_tags = array_merge($unsafe_tags, $custom_bbcodes);
    }
    foreach ($unsafe_tags as $tag) {
        if (($start_pos = strrpos($text, $tag[0])) > strrpos($text, $tag[1])) {
            $text = substr($text, 0, $start_pos) . ' ...';
        }
    }
    // Get all of the BBCodes the text contains.
    // If it does not contain any than just skip this step.
    // Preg expression is borrowed from strip_bbcode()
    if (preg_match_all("#\\[(\\/?)([a-z0-9_\\*\\+\\-]+)(?:=(&quot;.*&quot;|[^\\]]*))?(?::[a-z])?(?:\\:{$uid})\\]#", $text, $matches, PREG_PATTERN_ORDER) != 0) {
        $open_tags = array();
        for ($i = 0, $size = sizeof($matches[0]); $i < $size; ++$i) {
            $bbcode_name =& $matches[2][$i];
            $opening = $matches[1][$i] == '/' ? false : true;
            // If a new BBCode is opened add it to the array of open BBCodes
            if ($opening) {
                $open_tags[] = array('name' => $bbcode_name, 'plus' => $opening && $bbcode_name == 'list' && !empty($matches[3][$i]) ? ':o' : '');
            } else {
                array_pop($open_tags);
            }
        }
        // Sort open BBCode tags so the most recently opened will be the first (because it has to be closed first)
        krsort($open_tags);
        // Close remaining open BBCode tags
        foreach ($open_tags as $tag) {
            $text .= '[/' . $tag['name'] . $tag['plus'] . ':' . $uid . ']';
        }
    }
    return $text;
}
 /**
  * Generates default bitfield
  *
  * This bitfield decides which bbcodes are defined in a template.
  *
  * @return string Bitfield
  */
 function default_bitfield()
 {
     static $value;
     if (isset($value)) {
         return $value;
     }
     // Hardcoded template bitfield to add for new templates
     $bitfield = new bitfield();
     $bitfield->set(0);
     $bitfield->set(1);
     $bitfield->set(2);
     $bitfield->set(3);
     $bitfield->set(4);
     $bitfield->set(8);
     $bitfield->set(9);
     $bitfield->set(11);
     $bitfield->set(12);
     $value = $bitfield->get_base64();
     return $value;
 }
Example #9
0
    /**
     * Init bbcode cache
     *
     * requires: $this->bbcode_bitfield
     * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
     */
    function bbcode_cache_init()
    {
        global $phpbb_root_path, $phpEx, $config, $user, $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_path_helper, $phpbb_container, $phpbb_filesystem;
        if (empty($this->template_filename)) {
            $this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);
            $template = new \phpbb\template\twig\twig($phpbb_container->get('path_helper'), $phpbb_container->get('config'), new \phpbb\template\context(), new \phpbb\template\twig\environment($phpbb_container->get('config'), $phpbb_container->get('filesystem'), $phpbb_container->get('path_helper'), $phpbb_container, $phpbb_container->getParameter('core.root_path') . 'cache/', $phpbb_container->get('ext.manager'), new \phpbb\template\twig\loader($phpbb_filesystem)), $phpbb_container->getParameter('core.root_path') . 'cache/', $phpbb_container->get('user'), $phpbb_container->get('template.twig.extensions.collection'), $phpbb_extension_manager);
            $template->set_style();
            $template->set_filenames(array('bbcode.html' => 'bbcode.html'));
            $this->template_filename = $template->get_source_file_for_handle('bbcode.html');
        }
        $bbcode_ids = $rowset = $sql = array();
        $bitfield = new bitfield($this->bbcode_bitfield);
        $bbcodes_set = $bitfield->get_all_set();
        foreach ($bbcodes_set as $bbcode_id) {
            if (isset($this->bbcode_cache[$bbcode_id])) {
                // do not try to re-cache it if it's already in
                continue;
            }
            $bbcode_ids[] = $bbcode_id;
            if ($bbcode_id > NUM_CORE_BBCODES) {
                $sql[] = $bbcode_id;
            }
        }
        if (sizeof($sql)) {
            global $db;
            $sql = 'SELECT *
				FROM ' . BBCODES_TABLE . '
				WHERE ' . $db->sql_in_set('bbcode_id', $sql);
            $result = $db->sql_query($sql, 3600);
            while ($row = $db->sql_fetchrow($result)) {
                // To circumvent replacing newlines with <br /> for the generated html,
                // we use carriage returns here. They are later changed back to newlines
                $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
                $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
                $rowset[$row['bbcode_id']] = $row;
            }
            $db->sql_freeresult($result);
        }
        // To perform custom second pass in extension, use $this->bbcode_second_pass_by_extension()
        // method which accepts variable number of parameters
        foreach ($bbcode_ids as $bbcode_id) {
            switch ($bbcode_id) {
                case 0:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)), 'preg' => array('#\\[quote(?:=&quot;(.*?)&quot;)?:$uid\\]((?!\\[quote(?:=&quot;.*?&quot;)?:$uid\\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')"));
                    break;
                case 1:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id), '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id)));
                    break;
                case 2:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id), '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id)));
                    break;
                case 3:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[url:$uid\\]((.*?))\\[/url:$uid\\]#s' => $this->bbcode_tpl('url', $bbcode_id), '#\\[url=([^\\[]+?):$uid\\](.*?)\\[/url:$uid\\]#s' => $this->bbcode_tpl('url', $bbcode_id)));
                    break;
                case 4:
                    if ($user->optionget('viewimg')) {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[img:$uid\\](.*?)\\[/img:$uid\\]#s' => $this->bbcode_tpl('img', $bbcode_id)));
                    } else {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[img:$uid\\](.*?)\\[/img:$uid\\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true))));
                    }
                    break;
                case 5:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[size=([\\-\\+]?\\d+):$uid\\](.*?)\\[/size:$uid\\]#s' => $this->bbcode_tpl('size', $bbcode_id)));
                    break;
                case 6:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('!\\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\\-]+):$uid\\](.*?)\\[/color:$uid\\]!is' => $this->bbcode_tpl('color', $bbcode_id)));
                    break;
                case 7:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id), '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id)));
                    break;
                case 8:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[code(?:=([a-z]+))?:$uid\\](.*?)\\[/code:$uid\\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')"));
                    break;
                case 9:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#(\\[\\/?(list|\\*):[mou]?:?$uid\\])[\\n]{1}#' => "\$1", '#(\\[list=([^\\[]+):$uid\\])[\\n]{1}#' => "\$1", '#\\[list=([^\\[]+):$uid\\]#e' => "\$this->bbcode_list('\$1')"), 'str' => array('[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id), '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id), '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id), '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id), '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id), '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id)));
                    break;
                case 10:
                    $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[email:$uid\\]((.*?))\\[/email:$uid\\]#is' => $this->bbcode_tpl('email', $bbcode_id), '#\\[email=([^\\[]+):$uid\\](.*?)\\[/email:$uid\\]#is' => $this->bbcode_tpl('email', $bbcode_id)));
                    break;
                case 11:
                    if ($user->optionget('viewflash')) {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[flash=([0-9]+),([0-9]+):$uid\\](.*?)\\[/flash:$uid\\]#' => $this->bbcode_tpl('flash', $bbcode_id)));
                    } else {
                        $this->bbcode_cache[$bbcode_id] = array('preg' => array('#\\[flash=([0-9]+),([0-9]+):$uid\\](.*?)\\[/flash:$uid\\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))));
                    }
                    break;
                case 12:
                    $this->bbcode_cache[$bbcode_id] = array('str' => array('[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)), 'preg' => array('#\\[attachment=([0-9]+):$uid\\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)));
                    break;
                default:
                    if (isset($rowset[$bbcode_id])) {
                        if ($this->template_bitfield->get($bbcode_id)) {
                            // The bbcode requires a custom template to be loaded
                            if (!($bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))) {
                                // For some reason, the required template seems not to be available, use the default template
                                $bbcode_tpl = !empty($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
                            } else {
                                // In order to use templates with custom bbcodes we need
                                // to replace all {VARS} to corresponding backreferences
                                // Note that backreferences are numbered from bbcode_match
                                if (preg_match_all('/\\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\\}/', $rowset[$bbcode_id]['bbcode_match'], $m)) {
                                    foreach ($m[0] as $i => $tok) {
                                        $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
                                    }
                                }
                            }
                        } else {
                            // Default template
                            $bbcode_tpl = !empty($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
                        }
                        // Replace {L_*} lang strings
                        $bbcode_tpl = preg_replace('/{L_([A-Z0-9_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
                        if (!empty($rowset[$bbcode_id]['second_pass_replace'])) {
                            // The custom BBCode requires second-pass pattern replacements
                            $this->bbcode_cache[$bbcode_id] = array('preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl));
                        } else {
                            $this->bbcode_cache[$bbcode_id] = array('str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl));
                        }
                    } else {
                        $this->bbcode_cache[$bbcode_id] = false;
                    }
                    break;
            }
        }
        $bbcode_cache = $this->bbcode_cache;
        $bbcode_bitfield = $this->bbcode_bitfield;
        $bbcode_uid = $this->bbcode_uid;
        /**
         * Use this event to modify the bbcode_cache
         *
         * @event core.bbcode_cache_init_end
         * @var	array	bbcode_cache		The array of cached search and replace patterns of bbcodes
         * @var	string	bbcode_bitfield		The bbcode bitfield
         * @var	string	bbcode_uid			The bbcode uid
         * @since 3.1.3-RC1
         */
        $vars = array('bbcode_cache', 'bbcode_bitfield', 'bbcode_uid');
        extract($phpbb_dispatcher->trigger_event('core.bbcode_cache_init_end', compact($vars)));
        $this->bbcode_cache = $bbcode_cache;
        $this->bbcode_bitfield = $bbcode_bitfield;
        $this->bbcode_uid = $bbcode_uid;
    }
    /**
     * Set manager from acp_styles class.
     *
     * @return null
     */
    protected function set_manager()
    {
        $this->user->add_lang('acp/styles');
        if (!class_exists('acp_styles')) {
            include $this->root_path . 'includes/acp/acp_styles.' . $this->php_ext;
        }
        if (!defined('TEMPLATE_BITFIELD')) {
            // Hardcoded template bitfield to add for new templates
            $bitfield = new bitfield();
            $bitfield->set(0);
            $bitfield->set(1);
            $bitfield->set(2);
            $bitfield->set(3);
            $bitfield->set(4);
            $bitfield->set(8);
            $bitfield->set(9);
            $bitfield->set(11);
            $bitfield->set(12);
            define('TEMPLATE_BITFIELD', $bitfield->get_base64());
            unset($bitfield);
        }
        $this->manager = new acp_styles();
        // Fill the configuration variables
        $this->manager->style_cfg = $this->manager->template_cfg = $this->manager->theme_cfg = $this->manager->imageset_cfg = '
#
# phpBB {MODE} configuration file
#
# @package phpBB3
# @copyright (c) 2005 phpBB Group
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
#
#
# At the left is the name, please do not change this
# At the right the value is entered
# For on/off options the valid values are on, off, 1, 0, true and false
#
# Values get trimmed, if you want to add a space in front or at the end of
# the value, then enclose the value with single or double quotes.
# Single and double quotes do not need to be escaped.
#
#

# General Information about this {MODE}
name = {NAME}
copyright = {COPYRIGHT}
version = {VERSION}
';
        $this->manager->theme_cfg .= '
# Some configuration options

#
# You have to turn this option on if you want to use the
# path template variables ({T_IMAGESET_PATH} for example) within
# your css file.
# This is mostly the case if you want to use language specific
# images within your css file.
#
parse_css_file = {PARSE_CSS_FILE}
';
        $this->manager->template_cfg .= '
# Some configuration options

#
# You can use this function to inherit templates from another template.
# The template of the given name has to be installed.
# Templates cannot inherit from inheriting templates.
#';
        $this->manager->imageset_keys = array('logos' => array('site_logo'), 'buttons' => array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply'), 'icons' => array('icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe'), 'forums' => array('forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'), 'folders' => array('topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread'), 'polls' => array('poll_left', 'poll_center', 'poll_right'), 'ui' => array('upload_bar'), 'user' => array('user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10'));
    }
Example #11
0
 function bbcode_tpl($tpl_name, $bbcode_id = -1)
 {
     global $_CLASS;
     if (empty($bbcode_hardtpl)) {
         static $bbcode_hardtpl = array();
         $bbcode_hardtpl = array('b_open' => '<span style="font-weight: bold">', 'b_close' => '</span>', 'i_open' => '<span style="font-style: italic">', 'i_close' => '</span>', 'u_open' => '<span style="text-decoration: underline">', 'u_close' => '</span>', 'img' => '<img src="$1" alt="' . $_CLASS['core_user']->get_lang('IMAGE') . '" />', 'size' => '<span style="font-size: $1px; line-height: normal">$2</span>', 'color' => '<span style="color: $1">$2</span>', 'email' => '<a href="mailto:$1">$2</a>');
         $template_bitfield = new bitfield($this->template_bitfield);
     }
     if ($bbcode_id != -1 && !$template_bitfield->get($bbcode_id)) {
         return isset($bbcode_hardtpl[$tpl_name]) ? $bbcode_hardtpl[$tpl_name] : FALSE;
     }
     if (empty($this->bbcode_template)) {
         if (($tpl = file_get_contents($this->template_filename)) === false) {
             trigger_error('Could not load bbcode template', E_USER_ERROR);
         }
         // replace \ with \\ and then ' with \'.
         $tpl = str_replace('\\', '\\\\', $tpl);
         $tpl = str_replace("'", "\\'", $tpl);
         // strip newlines and indent
         $tpl = preg_replace("/\n[\n\r\\s\t]*/", '', $tpl);
         // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
         $this->bbcode_template = array();
         $matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);
         for ($i = 0; $i < $matches; $i++) {
             if (empty($match[1][$i])) {
                 continue;
             }
             $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
         }
     }
     return isset($this->bbcode_template[$tpl_name]) ? $this->bbcode_template[$tpl_name] : (isset($bbcode_hardtpl[$tpl_name]) ? $bbcode_hardtpl[$tpl_name] : false);
 }