Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refs #3531: Adds elgg_view_widgets and converts widgets layout to use…

… it.

Also improves grids to help with gutters and right-floated columns.
  • Loading branch information...
commit 00eb2b7dc5f7899c2c249e082fc22598e0417c64 1 parent e7d0eae
@ewinslow ewinslow authored
View
41 engine/lib/widgets.php
@@ -21,6 +21,18 @@
* @since 1.8.0
*/
function elgg_get_widgets($user_guid, $context) {
+ static $widget_cache;
+
+ if (!isset($widget_cache)) {
+ $widget_cache = array();
+ }
+
+ $widget_cache_key = "$context-$user_guid";
+
+ if (isset($widget_cache[$widget_cache_key])) {
+ return $widget_cache[$widget_cache_key];
+ }
+
$options = array(
'type' => 'object',
'subtype' => 'widget',
@@ -44,12 +56,39 @@ function elgg_get_widgets($user_guid, $context) {
foreach ($sorted_widgets as $col => $widgets) {
ksort($sorted_widgets[$col]);
- }
+ }
+
+ $widget_cache[$widget_cache_key] = $sorted_widgets;
return $sorted_widgets;
}
/**
+ * Output a single column of widgets.
+ *
+ * @param ElggUser $user The owner user entity.
+ * @param string $context The context (profile, dashboard, etc.)
+ * @param int $column Which column to output.
+ * @param bool $show_access Show the access control (true by default)
+ */
+function elgg_view_widgets($user, $context, $column, $show_access = true) {
+ $widgets = elgg_get_widgets($user->guid, $context);
+ $column_widgets = $widgets[$column];
+
+ $column_html = "<div class=\"elgg-widgets\" id=\"elgg-widget-col-$column\">";
@cash Owner
cash added a note

Shouldn't this be a view rather than hard coding this html?

@ewinslow Owner

We've done both before -- elgg_view_icon for example. Think a view would get us anything here?

@cash Owner
cash added a note

In general, putting html in a function is a bad idea because it cannot be overridden. When I get a chance I'll look to see how many other functions have hard coded html. I'm hoping very few do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (sizeof($column_widgets) > 0) {
+ foreach ($column_widgets as $widget) {
+ if (elgg_is_widget_type($widget->handler)) {
+ $column_html .= elgg_view_entity($widget, array('show_access' => $show_access));
+ }
+ }
+ }
+ $column_html .= '</div>';
+
+ return $column_html;
+}
+
+/**
* Create a new widget instance
*
* @param int $owner_guid GUID of entity that owns this widget
View
64 views/default/css/elements/grid.php
@@ -8,47 +8,27 @@
* To work around subpixel rounding discrepancies, apply .elgg-col-last to
* the last column (@todo we need broswer-specific test cases for this).
*/
+
+$gutterWidthPercent = 1.6; /* 16px on a 1000px grid */
?>
-/* ***************************************
- GRID
-*************************************** */
-.elgg-col {
- float: left;
-}
-.elgg-col-1of1 {
- float: none;
-}
-.elgg-col-1of2 {
- width: 50%;
-}
-.elgg-col-1of3 {
- width: 33.33%;
-}
-.elgg-col-2of3 {
- width: 66.66%;
-}
-.elgg-col-1of4 {
- width: 25%;
-}
-.elgg-col-3of4 {
- width: 75%;
-}
-.elgg-col-1of5 {
- width: 20%;
-}
-.elgg-col-2of5 {
- width: 40%;
-}
-.elgg-col-3of5 {
- width: 60%;
-}
-.elgg-col-4of5 {
- width: 80%;
-}
-.elgg-col-1of6 {
- width: 16.66%;
-}
-.elgg-col-5of6 {
- width: 83.33%;
-}
+.elgg-grid + .elgg-grid { margin-top: <?php echo $gutterWidthPercent; ?>%; }
+.elgg-col { float: left; margin-right: <?php echo $gutterWidthPercent; ?>%; }
+.elgg-col-alt { float: right; margin-left: <?php echo $gutterWidthPercent; ?>%; margin-right: 0; }
+.elgg-col-1of1 { float: none; margin: 0; }
+.elgg-col:last-child, .elgg-col-last { float: none; overflow: hidden; margin: 0; width: auto; }
+
+<?php
+
+for ($i = 2; $i <= 6; $i++) {
+ $gutters = $i - 1;
+ $columnWidthPercent = (100 - $gutters * $gutterWidthPercent)/$i;
+ for ($j = 1; $j < $i; $j++) {
+ if ($j > 1 && ($i/$j) === (int)($i/$j)) {
+ continue;
+ }
+
+ $widthPercent = $j * $columnWidthPercent + ($j - 1) * $gutterWidthPercent;
+ echo ".elgg-col-{$j}of{$i} { width: $widthPercent%; }\n";
+ }
+}
View
1  views/default/css/elements/modules.php
@@ -99,7 +99,6 @@
Widgets
*************************************** */
.elgg-widgets {
- float: right;
min-height: 30px;
}
.elgg-widget-add-control {
View
18 views/default/page/layouts/widgets.php
@@ -37,22 +37,14 @@
echo $vars['content'];
-$widget_class = "elgg-col-1of{$num_columns}";
+$widget_class = "elgg-col-alt elgg-col-1of{$num_columns}";
for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
- if (isset($widgets[$column_index])) {
- $column_widgets = $widgets[$column_index];
- } else {
- $column_widgets = array();
+ if ($column_index == $num_columns) {
+ $widget_class .= ' elgg-col-last';
}
- echo "<div class=\"$widget_class elgg-widgets\" id=\"elgg-widget-col-$column_index\">";
- if (sizeof($column_widgets) > 0) {
- foreach ($column_widgets as $widget) {
- if (array_key_exists($widget->handler, $widget_types)) {
- echo elgg_view_entity($widget, array('show_access' => $show_access));
- }
- }
- }
+ echo "<div class=\"$widget_class\">";
+ echo elgg_view_widgets($owner, $context, $column_index, $show_access);
echo '</div>';
}
Please sign in to comment.
Something went wrong with that request. Please try again.