Permalink
Browse files

feature(html): moves favicon registration to a hook

Makes it easier to remove all core branded favicons by unregistering
a hook handler.
  • Loading branch information...
hypeJunction committed May 18, 2016
1 parent e116e5f commit a4a35362eefbfa8449648b9834f29b9da0a7703c
Showing with 83 additions and 24 deletions.
  1. +32 −0 docs/guides/hooks-list.rst
  2. +51 −24 engine/lib/views.php
View
@@ -337,6 +337,38 @@ Views
**head, page**
In ``elgg_view_page()``, filters ``$vars['head']``
+ Return value contains an array with ``title``, ``metas`` and ``links`` keys,
+ where ``metas`` is an array of elements to be formatted as ``<meta>`` head tags,
+ and ``links`` is an array of elements to be formatted as ``<link>`` head tags.
+ Each meta and link element contains a set of key/value pairs that are formatted
+ into html tag attributes, e.g.
+
+.. code:: php
+
+ return [
+ 'title' => 'Current page title',
+ 'metas' => [
+ 'viewport' => [
+ 'name' => 'viewport',
+ 'content' => 'width=device-width',
+ ]
+ ],
+ 'links' => [
+ 'rss' => [
+ 'rel' => 'alternative',
+ 'type' => 'application/rss+xml',
+ 'title' => 'RSS',
+ 'href' => elgg_format_url($url),
+ ],
+ 'icon-16' => [
+ 'rel' => 'icon',
+ 'sizes' => '16x16',
+ 'type' => 'image/png',
+ 'href' => elgg_get_simplecache_url('favicon-16.png'),
+ ],
+ ],
+ ];
+
**ajax_response, view:<view>**
Filters ``ajax/view/`` responses before they're sent back to the ``elgg/Ajax`` module.
View
@@ -561,64 +561,87 @@ function _elgg_views_prepare_head($title) {
'name' => 'apple-mobile-web-app-capable',
'content' => 'yes',
);
- $params['links']['apple-touch-icon'] = array(
+
+ // RSS feed link
+ if (_elgg_has_rss_link()) {
+ $url = current_page_url();
+ if (substr_count($url,'?')) {
+ $url .= "&view=rss";
+ } else {
+ $url .= "?view=rss";
+ }
+ $params['links']['rss'] = array(
+ 'rel' => 'alternative',
+ 'type' => 'application/rss+xml',
+ 'title' => 'RSS',
+ 'href' => elgg_format_url($url),
+ );
+ }
+
+ return $params;
+}
+
+
+/**
+ * Add favicon link tags to HTML head
+ *
+ * @param string $hook "head"
+ * @param string $type "page"
+ * @param array $head_params Head params
+ * <code>
+ * [
+ * 'title' => '',
+ * 'metas' => [],
+ * 'links' => [],
+ * ]
+ * </code>
+ * @param array $params Hook params
+ * @return array
+ */
+function _elgg_views_prepare_favicon_links($hook, $type, $head_params, $params) {
+
+ $head_params['links']['apple-touch-icon'] = array(
'rel' => 'apple-touch-icon',
'href' => elgg_get_simplecache_url('favicon-128.png'),
);
// favicons
- $params['links']['icon-ico'] = array(
+ $head_params['links']['icon-ico'] = array(
'rel' => 'icon',
'href' => elgg_get_simplecache_url('favicon.ico'),
);
- $params['links']['icon-vector'] = array(
+ $head_params['links']['icon-vector'] = array(
'rel' => 'icon',
'sizes' => '16x16 32x32 48x48 64x64 128x128',
'type' => 'image/svg+xml',
'href' => elgg_get_simplecache_url('favicon.svg'),
);
- $params['links']['icon-16'] = array(
+ $head_params['links']['icon-16'] = array(
'rel' => 'icon',
'sizes' => '16x16',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-16.png'),
);
- $params['links']['icon-32'] = array(
+ $head_params['links']['icon-32'] = array(
'rel' => 'icon',
'sizes' => '32x32',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-32.png'),
);
- $params['links']['icon-64'] = array(
+ $head_params['links']['icon-64'] = array(
'rel' => 'icon',
'sizes' => '64x64',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-64.png'),
);
- $params['links']['icon-128'] = array(
+ $head_params['links']['icon-128'] = array(
'rel' => 'icon',
'sizes' => '128x128',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-128.png'),
);
- // RSS feed link
- if (_elgg_has_rss_link()) {
- $url = current_page_url();
- if (substr_count($url,'?')) {
- $url .= "&view=rss";
- } else {
- $url .= "?view=rss";
- }
- $params['links']['rss'] = array(
- 'rel' => 'alternative',
- 'type' => 'application/rss+xml',
- 'title' => 'RSS',
- 'href' => elgg_format_url($url),
- );
- }
-
- return $params;
+ return $head_params;
}
/**
@@ -1739,6 +1762,10 @@ function elgg_views_boot() {
elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options');
+ // registered with high priority for BC
+ // prior to 2.2 registration used to take place in _elgg_views_prepare_head() before the hook was triggered
+ elgg_register_plugin_hook_handler('head', 'page', '_elgg_views_prepare_favicon_links', 1);
+
// @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
$view_path = $GLOBALS['_ELGG']->view_path;
$viewtype_dirs = scandir($view_path);

0 comments on commit a4a3536

Please sign in to comment.