htmloutputter->script() special cases src's that begin with plugin/ or local/ so that plugins don't need to include common_path() in every call to $action->script()

Adjust plugins to not call common_path() when it's not necessary
Fix minify plugin
This commit is contained in:
Craig Andrews 2010-02-17 12:03:14 -05:00
parent c19300272f
commit 46e9aa13aa
10 changed files with 53 additions and 42 deletions

View File

@ -356,40 +356,47 @@ class HTMLOutputter extends XMLOutputter
if( empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment']))
{
$path = common_config('javascript', 'path');
if (strpos($src, 'plugins/') === 0 || strpos($src, 'local/') === 0) {
if (empty($path)) {
$path = common_config('site', 'path') . '/js/';
}
$src = common_path($src) . '?version=' . STATUSNET_VERSION;
if ($path[strlen($path)-1] != '/') {
$path .= '/';
}
}else{
if ($path[0] != '/') {
$path = '/'.$path;
}
$path = common_config('javascript', 'path');
$server = common_config('javascript', 'server');
if (empty($server)) {
$server = common_config('site', 'server');
}
$ssl = common_config('javascript', 'ssl');
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('javascript', 'server')) {
$ssl = true;
} else {
$ssl = false;
if (empty($path)) {
$path = common_config('site', 'path') . '/js/';
}
if ($path[strlen($path)-1] != '/') {
$path .= '/';
}
if ($path[0] != '/') {
$path = '/'.$path;
}
$server = common_config('javascript', 'server');
if (empty($server)) {
$server = common_config('site', 'server');
}
$ssl = common_config('javascript', 'ssl');
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('javascript', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
$src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION;
}
$protocol = ($ssl) ? 'https' : 'http';
$src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION;
}
$this->element('script', array('type' => $type,

View File

@ -42,8 +42,8 @@ class AutocompletePlugin extends Plugin
function onEndShowScripts($action){
if (common_logged_in()) {
$action->script(common_path('plugins/Autocomplete/jquery-autocomplete/jquery.autocomplete.pack.js'));
$action->script(common_path('plugins/Autocomplete/Autocomplete.js'));
$action->script('plugins/Autocomplete/jquery-autocomplete/jquery.autocomplete.pack.js');
$action->script('plugins/Autocomplete/Autocomplete.js');
}
}

View File

@ -68,7 +68,7 @@ class CometPlugin extends RealtimePlugin
$ours = array('jquery.comet.js', 'cometupdate.js');
foreach ($ours as $script) {
$scripts[] = common_path('plugins/Comet/'.$script);
$scripts[] = 'plugins/Comet/'.$script;
}
return $scripts;

View File

@ -181,7 +181,7 @@ class FacebookPlugin extends Plugin
if ($this->reqFbScripts($action)) {
$apikey = common_config('facebook', 'apikey');
$plugin_path = common_path('plugins/Facebook');
$plugin_path = 'plugins/Facebook';
$login_url = common_local_url('FBConnectAuth');
$logout_url = common_local_url('logout');

View File

@ -89,7 +89,7 @@ class FacebookAction extends Action
function showScripts()
{
$this->script(common_path('plugins/Facebook/facebookapp.js'));
$this->script('plugins/Facebook/facebookapp.js');
}
/**

View File

@ -40,8 +40,8 @@ class InfiniteScrollPlugin extends Plugin
function onEndShowScripts($action)
{
$action->script(common_path('plugins/InfiniteScroll/jquery.infinitescroll.js'));
$action->script(common_path('plugins/InfiniteScroll/infinitescroll.js'));
$action->script('plugins/InfiniteScroll/jquery.infinitescroll.js');
$action->script('plugins/InfiniteScroll/infinitescroll.js');
}
function onPluginVersion(&$versions)

View File

@ -86,7 +86,11 @@ class MinifyPlugin extends Plugin
$url = parse_url($src);
if( empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment']))
{
$src = $this->minifyUrl($src);
if (strpos($src, 'plugins/') === 0 || strpos($src, 'local/') === 0) {
$src = $this->minifyUrl($src);
} else {
$src = $this->minifyUrl('js/'.$src);
}
}
}

View File

@ -281,12 +281,12 @@ class OStatusPlugin extends Plugin
}
function onEndShowStatusNetStyles($action) {
$action->cssLink(common_path('plugins/OStatus/theme/base/css/ostatus.css'));
$action->cssLink('plugins/OStatus/theme/base/css/ostatus.css');
return true;
}
function onEndShowStatusNetScripts($action) {
$action->script(common_path('plugins/OStatus/js/ostatus.js'));
$action->script('plugins/OStatus/js/ostatus.js');
return true;
}
}

View File

@ -77,9 +77,9 @@ class OrbitedPlugin extends RealtimePlugin
$root = 'http://'.$server.(($port == 80) ? '':':'.$port);
$scripts[] = $root.'/static/Orbited.js';
$scripts[] = common_path('plugins/Orbited/orbitedextra.js');
$scripts[] = 'plugins/Orbited/orbitedextra.js';
$scripts[] = $root.'/static/protocols/stomp/stomp.js';
$scripts[] = common_path('plugins/Orbited/orbitedupdater.js');
$scripts[] = 'plugins/Orbited/orbitedupdater.js';
return $scripts;
}

View File

@ -117,7 +117,7 @@ class RealtimePlugin extends Plugin
function onEndShowStatusNetStyles($action)
{
$action->cssLink(common_path('plugins/Realtime/realtimeupdate.css'),
$action->cssLink('plugins/Realtime/realtimeupdate.css',
null, 'screen, projection, tv');
return true;
}
@ -307,7 +307,7 @@ class RealtimePlugin extends Plugin
function _getScripts()
{
return array(common_path('plugins/Realtime/realtimeupdate.js'));
return array('plugins/Realtime/realtimeupdate.js');
}
function _updateInitialize($timeline, $user_id)