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'])) 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)) { $src = common_path($src) . '?version=' . STATUSNET_VERSION;
$path = common_config('site', 'path') . '/js/';
}
if ($path[strlen($path)-1] != '/') { }else{
$path .= '/';
}
if ($path[0] != '/') { $path = common_config('javascript', 'path');
$path = '/'.$path;
}
$server = common_config('javascript', 'server'); if (empty($path)) {
$path = common_config('site', 'path') . '/js/';
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 ($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, $this->element('script', array('type' => $type,

View File

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

View File

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

View File

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

View File

@ -89,7 +89,7 @@ class FacebookAction extends Action
function showScripts() 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) function onEndShowScripts($action)
{ {
$action->script(common_path('plugins/InfiniteScroll/jquery.infinitescroll.js')); $action->script('plugins/InfiniteScroll/jquery.infinitescroll.js');
$action->script(common_path('plugins/InfiniteScroll/infinitescroll.js')); $action->script('plugins/InfiniteScroll/infinitescroll.js');
} }
function onPluginVersion(&$versions) function onPluginVersion(&$versions)

View File

@ -86,7 +86,11 @@ class MinifyPlugin extends Plugin
$url = parse_url($src); $url = parse_url($src);
if( empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment'])) 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) { 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; return true;
} }
function onEndShowStatusNetScripts($action) { function onEndShowStatusNetScripts($action) {
$action->script(common_path('plugins/OStatus/js/ostatus.js')); $action->script('plugins/OStatus/js/ostatus.js');
return true; return true;
} }
} }

View File

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

View File

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