~quam-plures-gatekeepers/quam-plures/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
 * This file implements the UI view for the widgets installed on a blog.
 *
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 * @package widgets
 */
if(!defined('QP_MAIN_INIT')) die('fail');

global $Blog;
global $container_list;
global $container_Widget_array;
global $rsc_url;

// Load widgets for current blog
$WidgetCache = & get_Cache( 'WidgetCache' );
$container_Widget_array = & $WidgetCache->get_by_blogID( $Blog->ID );

// fp> what browser do we need a fieldset for? fieldsets are cool at remembering their width :)
echo '<fieldset id="current_widgets">'."\n";

// Display containers for current template
foreach( $container_list as $container )
{
	display_container( $container );
}

// Display containers not in current template
foreach( $container_Widget_array as $container => $dummy )
{
	if( ! in_array( $container, $container_list ) )
	{
		display_container( $container, ' '.T_('[NOT INCLUDED IN SELECTED TEMPLATE!]') );
	}
}

echo '<img src="'.$rsc_url.'img/blank.gif" width="1" height="1" /><!-- for IE -->';
echo '</fieldset>'."\n";
echo '<img src="'.$rsc_url.'/img/blank.gif" width="1" height="1" class="clear">';

/**
 * Display a container
 *
 * @param string Title of the container. This gets passed to T_()!
 * @param string Suffix of legend
 */
function display_container( $container, $legend_suffix = '' )
{
	global $Blog;
	global $edited_ComponentWidget;

	$Table = new Table();
	$Table->title = '<span class="container_name">'.T_( $container ).'</span>'.$legend_suffix;
	// Table ID - fp> needs to be handled cleanly by Table object
	// fp> Using the container name which has special chars is a bad idea. Counter would be better
	$table_id = str_replace( ' ', '_', $container );
	$Table->global_icon( T_('Add a widget...'), 'new',
		regenerate_url( '', 'action=new&amp;container='.rawurlencode( $container ) ),
		/* TRANS: link used to add a new widget */ T_('Add widget').' &raquo;', array( 'id' => 'add_new_'.$table_id ) );

	$Table->cols = array(
		array( 'th' => /* TRANS: shortcut for enabled */ T_('En'), 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap' ),
		array( 'th' => T_('Widget') ),
		array( 'th' => T_('Type') ),
		array( 'th' => T_('Move'), 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap' ),
		array( 'th' => T_('Actions'), 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap' ),
	);

	$Table->display_init();

	// add ID for jQuery
	$Table->params['head_title'] = str_replace( '<table', '<table id="'.$table_id.'"', $Table->params['head_title'] );

	/*
	if( $legend_suffix )
	{
		// add jQuery no-drop -- fp> what do we need this one for?
		$Table->params['head_title'] = str_replace( 'class="grouped"', 'class="grouped no-drop"', $Table->params['head_title'] );
	}
	*/

	$Table->display_list_start();

	// title / column headers
	$Table->display_head();

	// body start
	$Table->display_body_start();

	$WidgetCache = & get_Cache( 'WidgetCache' );
	$Widget_array = & $WidgetCache->get_by_blog_container( $Blog->ID, $container );

	if( empty( $Widget_array ) )
	{
		$Table->display_line_start( true );
		$Table->display_col_start();
		echo '<span class="new_widget">'.T_('There is no widget in this container yet.').'</span>';
		$Table->display_col_end();
		$Table->display_line_end();
	}
	else
	{
		$widget_count = 0;
		foreach( $Widget_array as $ComponentWidget )
		{
			$widget_count++;
			$enabled = $ComponentWidget->get( 'enabled' );

			if( isset( $edited_ComponentWidget ) && $edited_ComponentWidget->ID == $ComponentWidget->ID )
			{
				$fadeout = true;
			}
			else
			{
				$fadeout = false;
			}

			$Table->display_line_start( false, $fadeout );

			$Table->display_col_start();
			if( $enabled )
			{
				// Indicator for the JS UI
				echo '<span class="widget_is_enabled">';
				echo get_icon( 'enabled', 'imgtag', array( 'title' => T_('The widget is enabled.') ) );
				echo '</span>';
			}
			else
			{
				echo get_icon( 'disabled', 'imgtag', array( 'title' => T_('The widget is disabled.') ) );
			}
			$Table->display_col_end();

			$Table->display_col_start();
			$ComponentWidget->init_display( array() );
			echo '<a href="'.regenerate_url( 'blog', 'action=edit&amp;wi_ID='.$ComponentWidget->ID ).'" class="widget_name">'
				.$ComponentWidget->get_desc_for_list().'</a>';
			$Table->display_col_end();

			// Note: this is totally useless, but we need more cols for the screen to feel "right":
			$Table->display_col_start();
			echo $ComponentWidget->type;
			$Table->display_col_end();

			// Move
			$Table->display_col_start();
			if( $widget_count > 1 )
			{
				echo action_icon( T_('Move up!'), 'move_up', regenerate_url( 'blog', 'action=move_up&amp;wi_ID='.$ComponentWidget->ID ) );
			}
			else
			{
				echo get_icon( 'nomove', 'imgtag', array( 'class' => 'action_icon' ) );
			}
			if( $widget_count < count( $Widget_array ) )
			{
				echo action_icon( T_('Move down!'), 'move_down', regenerate_url( 'blog', 'action=move_down&amp;wi_ID='.$ComponentWidget->ID ) );
			}
			else
			{
				echo get_icon( 'nomove', 'imgtag', array( 'class' => 'action_icon' ) );
			}
			$Table->display_col_end();

			// Actions
			$Table->display_col_start();
			if( $enabled )
			{
				echo action_icon( T_('Disable this widget!'), 'deactivate', regenerate_url( 'blog', 'action=toggle&amp;wi_ID='.$ComponentWidget->ID ) );
			}
			else
			{
				echo action_icon( T_('Enable this widget!'), 'activate', regenerate_url( 'blog', 'action=toggle&amp;wi_ID='.$ComponentWidget->ID ) );
			}
			echo '<span class="edit_icon_hook">'.action_icon( T_('Edit widget settings!'), 'edit', regenerate_url( 'blog', 'action=edit&amp;wi_ID='.$ComponentWidget->ID ) ).'</span>';
			echo '<span class="delete_icon_hook">'.action_icon( T_('Remove this widget!'), 'delete', regenerate_url( 'blog', 'action=delete&amp;wi_ID='.$ComponentWidget->ID ) ).'</span>';
			$Table->display_col_end();
			$Table->display_line_end();
		}
	}
	// BODY END
	$Table->display_body_end();
	$Table->display_list_end();
}

?>