mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 08:47:45 +02:00
[ticket/10390] Allow option for jQuery to be hosted by a remote CDN
Add an option to the ACP so admins can choose to host jQuery from the local version shipped with phpBB, or via a popular CDN. PHPBB3-10390
This commit is contained in:
@@ -99,6 +99,7 @@ class acp_board
|
||||
'load_cpf_pm' => array('lang' => 'LOAD_CPF_PM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'load_cpf_viewprofile' => array('lang' => 'LOAD_CPF_VIEWPROFILE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'load_cpf_viewtopic' => array('lang' => 'LOAD_CPF_VIEWTOPIC', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'load_jquery_host' => array('lang' => 'JQUERY_HOST', 'validate' => 'string', 'type' => 'select', 'method' => 'jquery_host_select', 'explain' => true),
|
||||
|
||||
'legend3' => 'ACP_SUBMIT_CHANGES',
|
||||
)
|
||||
@@ -997,4 +998,14 @@ class acp_board
|
||||
$cache->destroy('sql', FORUMS_TABLE);
|
||||
}
|
||||
|
||||
function jquery_host_select($value, $key = '')
|
||||
{
|
||||
global $user;
|
||||
|
||||
return '<option value="localhost"' . (($value == 'localhost') ? ' selected="selected"' : '') . '>' . $user->lang['JQUERY_HOST_LOCAL'] . '</option>
|
||||
<option value="google"' . (($value == 'google') ? ' selected="selected"' : '') . '>' . $user->lang['JQUERY_HOST_GOOGLE'] . '</option>
|
||||
<option value="microsoft"' . (($value == 'microsoft') ? ' selected="selected"' : '') . '>' . $user->lang['JQUERY_HOST_MS'] . '</option>
|
||||
<option value="jquery"' . (($value == 'jquery') ? ' selected="selected"' : '') . '>' . $user->lang['JQUERY_HOST_JQUERY'] . '</option>';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -210,6 +210,7 @@ define('CAPTCHA_MAX_CHARS', 7);
|
||||
|
||||
// Additional constants
|
||||
define('VOTE_CONVERTED', 127);
|
||||
define('JQUERY_VERSION', '1.6.2'); // Important follow jQuery versioning, ie: 1.6, 1.6.1, 1.6.2
|
||||
|
||||
// Table names
|
||||
define('ACL_GROUPS_TABLE', $table_prefix . 'acl_groups');
|
||||
|
@@ -4569,6 +4569,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
||||
'T_STYLESHEET_LINK' => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css',
|
||||
'T_STYLESHEET_LANG_LINK' => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/' . $user->lang_name . '/stylesheet.css',
|
||||
'T_STYLESHEET_NAME' => $user->theme['theme_name'],
|
||||
'T_JQUERY_LINK' => (!empty($config['load_jquery_host']) && $config['load_jquery_host'] != 'localhost') ? remote_jquery_url($config['load_jquery_host']) : "{$web_path}assets/javascript/jquery.js",
|
||||
'S_JQUERY_FALLBACK' => (!empty($config['load_jquery_host']) && $config['load_jquery_host'] != 'localhost') ? true : false,
|
||||
|
||||
'T_THEME_NAME' => $user->theme['theme_path'],
|
||||
'T_THEME_LANG_NAME' => $user->data['user_lang'],
|
||||
@@ -4767,3 +4769,30 @@ function phpbb_pcre_utf8_support()
|
||||
}
|
||||
return $utf8_pcre_properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build jQuery URL for remote CDNs
|
||||
* Reference: http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery
|
||||
*
|
||||
* @return string Returns url to a jQuery library
|
||||
*/
|
||||
function remote_jquery_url($host)
|
||||
{
|
||||
switch($host)
|
||||
{
|
||||
case 'google':
|
||||
// Google uses a 1.5.0, 1.5.1 format (it is always a three numbered version)
|
||||
return '//ajax.googleapis.com/ajax/libs/jquery/' . ((strlen(JQUERY_VERSION) == 3) ? JQUERY_VERSION . '.0' : JQUERY_VERSION) . '/jquery.min.js';
|
||||
break;
|
||||
|
||||
case 'microsoft':
|
||||
// Microsoft uses a 1.5, 1.5.1 format
|
||||
return 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' . JQUERY_VERSION . '.min.js';
|
||||
break;
|
||||
|
||||
case 'jquery':
|
||||
// jQuery uses a 1.5, 1.5.1 format
|
||||
return 'http://code.jquery.com/jquery-' . JQUERY_VERSION . '.min.js';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -126,6 +126,8 @@ function adm_page_footer($copyright_html = true)
|
||||
'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '',
|
||||
'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
|
||||
'S_COPYRIGHT_HTML' => $copyright_html,
|
||||
'T_JQUERY_LINK' => (!empty($config['load_jquery_host']) && $config['load_jquery_host'] != 'localhost') ? remote_jquery_url($config['load_jquery_host']) : "{$phpbb_root_path}assets/javascript/jquery.js",
|
||||
'S_JQUERY_FALLBACK' => (!empty($config['load_jquery_host']) && $config['load_jquery_host'] != 'localhost') ? true : false,
|
||||
'VERSION' => $config['version'])
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user