Permalink
Browse files

feature(views): Nearly all plugin static resources are in views

Makes elgg.get_simplecache_url() match the PHP version.
Associates .swf files with the right Content-Type.
groups/icon.php sends the right Content-Type for gifs.
  • Loading branch information...
mrclay committed Jun 20, 2015
1 parent 8e58261 commit b8a8864c6a0816d59a39ff42926cceb010bcfa0f
@@ -242,7 +242,9 @@ protected function getContentType($view) {
case 'html':
case 'xml':
return "text/$extension";
-
+
+ case 'swf':
+ return 'application/x-shockwave-flash';
default:
break;
}
View
@@ -12,20 +12,27 @@ elgg.get_site_url = function() {
/**
* Get the URL for the cached file
*
- * @param {String} type
- * @param {String} view
+ * @param {String} view The full view name
+ * @param {String} subview If the first arg is "css" or "js", the rest of the view name
* @return {String} The site URL.
*/
-elgg.get_simplecache_url = function(type, view) {
- var lastcache;
+elgg.get_simplecache_url = function(view, subview) {
+ var lastcache, path;
+
if (elgg.config.simplecache_enabled) {
lastcache = elgg.config.lastcache;
} else {
lastcache = 0;
}
- if ((type === 'js' || type === 'css') && 0 === view.indexOf(type + '/')) {
- view = view.substr(type.length + 1);
+
+ if (!subview) {
+ path = '/cache/' + lastcache + '/' + elgg.config.viewtype + '/' + view;
+ } else {
+ if ((view === 'js' || view === 'css') && 0 === subview.indexOf(view + '/')) {
+ subview = subview.substr(view.length + 1);
+ }
+ path = '/cache/' + lastcache + '/' + elgg.config.viewtype + '/' + view + '/' + subview;
}
- var path = '/cache/' + lastcache + '/' + elgg.config.viewtype + '/' + type + '/' + view;
+
return elgg.normalize_url(path);
};
@@ -109,7 +109,7 @@ function aalborg_theme_setup_head($hook, $type, $data) {
$data['links']['apple-touch-icon'] = array(
'rel' => 'apple-touch-icon',
- 'href' => elgg_normalize_url('mod/aalborg_theme/graphics/homescreen.png'),
+ 'href' => elgg_get_simplecache_url('aalborg_theme/homescreen.png'),
);
return $data;
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'aalborg_theme/avatar_menu_arrows.png' => __DIR__ . '/graphics/avatar_menu_arrows.png',
+ 'allborg_theme/homescreen.png' => __DIR__ . '/graphics/homescreen.png',
+ ],
+];
@@ -110,13 +110,13 @@
.elgg-icon-hover-menu-hover,
.elgg-icon-hover-menu:hover,
:focus > .elgg-icon-hover-menu {
- background: transparent url(<?php echo elgg_get_site_url();?>mod/aalborg_theme/graphics/avatar_menu_arrows.png) no-repeat;
+ background: transparent url(<?= elgg_get_simplecache_url('aalborg_theme/avatar_menu_arrows.png') ?>) no-repeat;
background-position: right bottom;
width: 100%;
height: 100%;
}
.elgg-icon-hover-menu {
- background: transparent url(<?php echo elgg_get_site_url();?>mod/aalborg_theme/graphics/avatar_menu_arrows.png) no-repeat;
+ background: transparent url(<?= elgg_get_simplecache_url('aalborg_theme/avatar_menu_arrows.png') ?>) no-repeat;
background-position: right bottom;
width: 100%;
height: 100%;
@@ -65,16 +65,16 @@
display: block;
}
#notificationstable td.emailtogglefield a.emailtoggleOff {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_email.gif) no-repeat right 2px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_email.gif'); ?>) no-repeat right 2px;
}
#notificationstable td.emailtogglefield a.emailtoggleOn {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_email.gif) no-repeat right -36px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_email.gif'); ?>) no-repeat right -36px;
}
#notificationstable td.sitetogglefield a.sitetoggleOff {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_site.gif) no-repeat right 2px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_site.gif'); ?>) no-repeat right 2px;
}
#notificationstable td.sitetogglefield a.sitetoggleOn {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_site.gif) no-repeat right -37px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_site.gif'); ?>) no-repeat right -37px;
}
.notification_friends,
.notification_personal,
View
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'bookmarks/bookmark.gif' => __DIR__ . '/graphics/bookmark.gif',
+ 'bookmarks/bookmarklet.gif' => __DIR__ . '/graphics/bookmarklet.gif',
+ ],
+];
@@ -21,7 +21,7 @@
$url = elgg_get_site_url();
$img = elgg_view('output/img', array(
- 'src' => 'mod/bookmarks/graphics/bookmarklet.gif',
+ 'src' => elgg_get_simplecache_url('bookmarks/bookmarklet.gif'),
'alt' => $title,
));
$bookmarklet = "<a href=\"javascript:location.href='{$url}bookmarks/add/$guid?address='"
@@ -1,3 +1,3 @@
.elgg-icon-bookmark {
- background: transparent url(<?php echo elgg_get_site_url();?>mod/bookmarks/graphics/bookmark.gif);
+ background: transparent url(<?= elgg_get_simplecache_url('bookmarks/bookmark.gif'); ?>);
}
View
@@ -15,11 +15,9 @@ function ckeditor_init() {
elgg_extend_view('css/elgg/wysiwyg.css', 'css/elements/typography', 100);
elgg_define_js('ckeditor', array(
- 'src' => '/mod/ckeditor/vendors/ckeditor/ckeditor.js',
'exports' => 'CKEDITOR',
));
elgg_define_js('jquery.ckeditor', array(
- 'src' => '/mod/ckeditor/vendors/ckeditor/adapters/jquery.js',
'deps' => array('jquery', 'ckeditor'),
'exports' => 'jQuery.fn.ckeditor',
));
View
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'js/ckeditor.js' => __DIR__ . '/vendors/ckeditor/ckeditor.js',
+ 'js/jquery.ckeditor.js' => __DIR__ . '/vendors/ckeditor/adapters/jquery.js',
+ ],
+];
@@ -3,7 +3,7 @@ define(function(require) {
var $ = require('jquery'); require('jquery.ckeditor');
var CKEDITOR = require('ckeditor');
- CKEDITOR.plugins.addExternal('blockimagepaste', elgg.get_site_url() + 'mod/ckeditor/views/default/js/elgg/ckeditor/blockimagepaste.js', '');
+ CKEDITOR.plugins.addExternal('blockimagepaste', elgg.get_simplecache_url('js/elgg/ckeditor/blockimagepaste.js'), '');
var elggCKEditor = {
@@ -13,7 +13,7 @@ define(function(require) {
language: elgg.get_language(),
skin: 'moono',
uiColor: '#EEEEEE',
- contentsCss: elgg.get_simplecache_url('css', 'elgg/wysiwyg.css'),
+ contentsCss: elgg.get_simplecache_url('css/elgg/wysiwyg.css'),
disableNativeSpellChecker: false,
disableNativeTableHandles: false,
removeDialogTabs: 'image:advanced;image:Link;link:advanced;link:target',
View
@@ -23,11 +23,10 @@ function developers_init() {
elgg_register_action('developers/settings', "$action_base/settings.php", 'admin');
elgg_define_js('jquery.jstree', array(
- 'src' => '/mod/developers/vendors/jsTree/jquery.jstree.js',
'exports' => 'jQuery.fn.jstree',
'deps' => array('jquery'),
));
- elgg_register_css('jquery.jstree', '/mod/developers/vendors/jsTree/themes/default/style.css');
+ elgg_register_css('jquery.jstree', elgg_get_simplecache_url('jquery.jstree.css'));
elgg_require_js('elgg/dev');
}
View
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'js/jquery.jstree.js' => __DIR__ . '/vendors/jsTree/jquery.jstree.js',
+ 'jquery.jstree.css' => __DIR__ . '/vendors/jsTree/themes/default/style.css',
+ ],
+];
View
@@ -239,8 +239,8 @@ function file_owner_block_menu($hook, $type, $return, $params) {
/**
* Registers page menu items for file type filtering and returns a view
*
- * @param int $container_guid The GUID of the container of the files
- * @param bool $friends Whether we're looking at the container or the container's friends
+ * @param int $container_guid The GUID of the container of the files
+ * @param bool $friends Whether we're looking at the container or the container's friends
*
* @return string The typecloud
*/
@@ -414,7 +414,7 @@ function file_set_icon_url($hook, $type, $url, $params) {
$ext = '';
}
- $url = "mod/file/graphics/icons/{$type}{$ext}.gif";
+ $url = elgg_get_simplecache_url("file/icons/{$type}{$ext}.gif");
$url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url);
return $url;
}
View
@@ -0,0 +1,16 @@
+<?php
+
+return call_user_func(function() {
+ $dir = dir(__DIR__ . '/graphics/icons');
+ $ret = [];
+
+ while (false !== ($entry = $dir->read())) {
+ if ($entry[0] === '.') {
+ continue;
+ }
+
+ $ret['default']["file/icons/$entry"] = "{$dir->path}/$entry";
+ }
+
+ return $ret;
+});
View
@@ -43,11 +43,12 @@
}
if (!$success) {
- $location = elgg_get_plugins_path() . "groups/graphics/default{$size}.gif";
- $contents = @file_get_contents($location);
+ $contents = elgg_view("groups/default{$size}.gif");
+ header("Content-type: image/gif");
+} else {
+ header("Content-type: image/jpeg");
}
-header("Content-type: image/jpeg");
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
header("Pragma: public");
header("Cache-Control: public");
View
@@ -329,7 +329,7 @@ function groups_set_icon_url($hook, $type, $url, $params) {
return "groupicon/$group->guid/$size/$icontime.jpg";
}
- return "mod/groups/graphics/default{$size}.gif";
+ return elgg_get_simplecache_url("groups/default{$size}.gif");
}
/**
View
@@ -0,0 +1,9 @@
+<?php
+
+return call_user_func(function() {
+ foreach (['large', 'medium', 'small', 'tiny'] as $size) {
+ $ret['default']["groups/default$size.gif"] = __DIR__ . "/graphics/default$size.gif";
+ }
+
+ return $ret;
+});
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'notifications/icon_notifications_email.gif' => __DIR__ . '/graphics/icon_notifications_email.gif',
+ 'notifications/icon_notifications_site.gif' => __DIR__ . '/graphics/icon_notifications_site.gif',
+ ],
+];
@@ -64,16 +64,16 @@
display: block;
}
#notificationstable td.emailtogglefield a.emailtoggleOff {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_email.gif) no-repeat right 2px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_email.gif'); ?>) no-repeat right 2px;
}
#notificationstable td.emailtogglefield a.emailtoggleOn {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_email.gif) no-repeat right -36px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_email.gif'); ?>) no-repeat right -36px;
}
#notificationstable td.sitetogglefield a.sitetoggleOff {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_site.gif) no-repeat right 2px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_site.gif'); ?>) no-repeat right 2px;
}
#notificationstable td.sitetogglefield a.sitetoggleOn {
- background: url(<?php echo elgg_get_site_url(); ?>mod/notifications/graphics/icon_notifications_site.gif) no-repeat right -37px;
+ background: url(<?= elgg_get_simplecache_url('notifications/icon_notifications_site.gif'); ?>) no-repeat right -37px;
}
.notification_friends,
.notification_personal,
View
@@ -205,10 +205,10 @@ function pages_icon_url_override($hook, $type, $returnvalue, $params) {
case 'topbar':
case 'tiny':
case 'small':
- return 'mod/pages/images/pages.gif';
+ return elgg_get_simplecache_url('pages/pages.gif');
break;
default:
- return 'mod/pages/images/pages_lrg.gif';
+ return elgg_get_simplecache_url('pages/pages_lrg.gif');
break;
}
}
View
@@ -0,0 +1,7 @@
+<?php
+return [
+ 'default' => [
+ 'pages/pages.gif' => __DIR__ . '/images/pages.gif',
+ 'pages/pages_lrg.gif' => __DIR__ . '/images/pages_lrg.gif',
+ ],
+];
@@ -0,0 +1,7 @@
+<?php
+
+return [
+ 'default' => [
+ 'reportedcontent/icon_reportthis.gif' => __DIR__ . '/graphics/icon_reportthis.gif',
+ ],
+];
@@ -10,5 +10,5 @@
?>
/* Reported Content */
.elgg-icon-report-this {
- background: url(<?php echo elgg_get_site_url(); ?>mod/reportedcontent/graphics/icon_reportthis.gif) no-repeat left top;
+ background: url(<?php echo elgg_get_simplecache_url('reportedcontent/icon_reportthis.gif'); ?>) no-repeat left top;
}
@@ -0,0 +1,9 @@
+<?php
+
+return [
+ 'default' => [
+ 'twitter_api/sign-in-with-twitter-d.png' => __DIR__ . '/graphics/sign-in-with-twitter-d.png',
+ 'twitter_api/sign-in-with-twitter-l.png' => __DIR__ . '/graphics/sign-in-with-twitter-l.png',
+ 'twitter_api/sign-in-with-twitter.gif' => __DIR__ . '/graphics/sign-in-with-twitter.gif',
+ ],
+];
@@ -4,7 +4,7 @@
*/
$url = elgg_get_site_url() . 'twitter_api/forward';
-$img_url = elgg_get_site_url() . 'mod/twitter_api/graphics/sign-in-with-twitter-d.png';
+$img_url = elgg_get_simplecache_url('twitter_api/sign-in-with-twitter-d.png');
$login = <<<__HTML
<div class="login_with_twitter">
View
@@ -14,11 +14,9 @@ function zaudio_init() {
elgg_extend_view('css/elgg', 'zaudio/css');
elgg_define_js('AudioPlayer', [
- 'src' => 'mod/zaudio/audioplayer/audio-player.20150521.min.js',
'exports' => 'AudioPlayer',
]);
// leave library registered for BC
- $js_url = elgg_get_site_url() . 'mod/zaudio/audioplayer/audio-player.20150521.min.js';
- elgg_register_js('elgg.zaudio', $js_url);
+ elgg_register_js('elgg.zaudio', elgg_get_simplecache_url('js/AudioPlayer.js'));
}
View
@@ -0,0 +1,8 @@
+<?php
+
+return [
+ 'default' => [
+ 'js/AudioPlayer.js' => __DIR__ . '/audioplayer/audio-player.20150521.min.js',
+ 'AudioPlayer.swf' => __DIR__ . '/audioplayer/player.20150521.swf',
+ ],
+];
@@ -7,7 +7,7 @@ define(function (require) {
// for unique IDs
var i = 0;
- AudioPlayer.setup(elgg.get_site_url() + "mod/zaudio/audioplayer/player.20150521.swf", {width: 290});
+ AudioPlayer.setup(elgg.get_simplecache_url('AudioPlayer.swf'), {width: 290});
function embed(element) {
var config = $(element).data().zaudioPlayer;

0 comments on commit b8a8864

Please sign in to comment.