public/wordpress/wp-content/plugins/backupbuddy/pluginbuddy/classes/ui.php
/*	pluginbuddy_ui->list_table()
	 *	
	 *	Displays a nice table with multiple columns, rows, bulk actions, hover actions, etc similar to WordPress posts table.
	 *	Currently only supports echo of output.
	 *	
	 *	@param		array		$items		Array of rows to display. Each row array contains an array with the columns. Typically set in controller.
	 *										Ex: array( array( 'blue', 'red' ), array( 'brown', 'green' ) ).
	 *										If the value for an item is an array then the first value will be assigned to the rel tag of any hover actions. If not
	 *										an array then the value itself will be put in the rel tag.  If an array the second value will be the one displayed in the column.
	 *										BackupBuddy needed the displayed item in the column to be a link (for downloading backups) but the backup file as the rel.
	 *	@param		array		$settings	Array of all the various settings. Merged with defaults prior to usage. Typically set in view.
	 *										See $default_settings at beginning of function for available settings.
	 *										Ex: $settings = array(
	 *												'action'		=>		pb_backupbuddy::plugin_url(),
	 *												'columns'		=>		array( 'Group Name', 'Images', 'Shortcode' ),
	 *												'hover_actions'	=>		array( 'edit' => 'Edit Group Settings' ),		// Slug can be a URL. In this case the value of the hovered row will be appended to the end of the URL. TODO: Make the first hover action be the link for the first listed item.
	 *												'bulk_actions'	=>		array( 'delete_images' => 'Delete' ),
	 *											);
	 *	@return		null
	 */


Displays a nice table with multiple columns, rows, bulk actions, hover actions, etc similar to WordPress posts table.
Currently only supports echo of output.

@param          array           $items          Array of rows to display. Each row array contains an array with the columns. Typically set in controller.
Displays a nice table with multiple columns rows bulk actions hover actions etc similar to WordPress posts table . Currently only supports echo of output . @param array $items Array of rows to display . Each row array contains an array with the columns . Typically set in controller .
public static function list_table( $items, $settings ) {
		$default_settings = array(
								'columns'					=>	array(),
								'hover_actions'				=>	array(),
								'bulk_actions'				=>	array(),
								'hover_action_column_key'	=>	'',			
								'action'					=>	'',
								'reorder'					=>	'',
								'after_bulk'				=>	'',
								'css'						=>	'',
							);
		$settings = array_merge( $default_settings, $settings );
		if ( !function_exists( 'bulk_actions' ) ) {
			function bulk_actions( $settings, $hover_note = false ) {
				if ( count( $settings['bulk_actions'] ) > 0 ) {
					echo '<div style="padding-bottom: 3px; padding-top: 3px;">';
					if ( count( $settings['bulk_actions'] ) == 1 ) {
						foreach( $settings['bulk_actions'] as $action_slug => $action_title ) {
							echo '<input type="hidden" name="bulk_action" value="' . $action_slug . '">';
							echo '<input type="submit" name="do_bulk_action" value="' . $action_title . '" class="button secondary-button backupbuddy-do_bulk_action">';
						}
					} else {
						echo '<select name="bulk_action" class="actions">';
						foreach ( $settings['bulk_actions'] as $action_slug => $action_title ) {
							echo '<option>Bulk Actions</option>';
							echo '<option value="' . $action_slug . '">' . $action_title . '</option>';
						}
						echo '</select> &nbsp;';
						echo '<input type="submit" name="do_bulk_action" value="Apply" class="button secondary-button backupbuddy-do_bulk_action">';
					}
					echo '&nbsp;&nbsp;';
					echo $settings['after_bulk'];
					echo '<div class="alignright actions">';
					if ( $hover_note === true ) {
						echo pb_backupbuddy::$ui->note( 'Hover over items above for additional options.' );
					}
					if ( $settings['reorder'] != '' ) {
						echo '	<input type="submit" name="save_order" id="save_order" value="Save Order" class="button-secondary" />';
					}
					echo '</div>';
					echo '</div>';
				}
			} 
		} 
		if ( $settings['action'] != '' ) {
			echo '<form method="post" action="' . $settings['action'] . '">';
			pb_backupbuddy::nonce();
			if ( $settings['reorder'] != '' ) {
				echo '<input type="hidden" name="order" value="" id="pb_order">';
			}
		}
		echo '<div style="width: 70%; min-width: 720px; ' . $settings['css'] . '">';
		bulk_actions( $settings );
		echo '<table class="widefat striped"';
		echo ' id="test">';
		echo '		<thead>
					<tr class="thead">';
		if ( count( $settings['bulk_actions'] ) > 0 ) {
			echo'		<th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>';
		}
		foreach ( $settings['columns'] as $column ) {
			echo '<th>' . $column . '</th>';
		}
		echo '		</tr>
				</thead>
			<tfoot>
				<tr class="thead">';
		if ( count( $settings['bulk_actions'] ) > 0 ) {
			echo'	<th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>';
		}
		foreach ( $settings['columns'] as $column ) {
			echo '<th>' . $column . '</th>';
		}
		echo '	</tr>
			</tfoot>
			<tbody';
		if ( $settings['reorder'] != '' ) {
			echo ' class="pb_reorder"';
		}
		echo '>';
		foreach ( (array)$items as $item_id => $item ) {
			echo '	<tr class="entry-row" id="pb_rowitem-' . $item_id . '">';
			if ( count( $settings['bulk_actions'] ) > 0 ) {
				echo'	<th scope="row" class="check-column"><input type="checkbox" name="items[]" class="entries" value="' . $item_id . '"></th>';
			}
			echo '		<td>';
			if ( is_array( $item['0'] ) ) {
				if ( $item['0'][1] == '' ) {
					echo '&nbsp;';
				} else {
					echo $item['0'][1];
				}
			} else {
				if ( $item['0'] == '' ) {
					echo '&nbsp;';
				} else {
					echo $item['0'];
				}
			}
			echo '			<div class="row-actions" style="margin-top: 10px;">'; 
			$i = 0;
			foreach ( $settings['hover_actions'] as $action_slug => $action_title ) { 
				$i++;
				if ( $settings['hover_action_column_key'] != '' ) {
					if ( is_array( $item[$settings['hover_action_column_key']] ) ) {
						$hover_action_column_value = $item[$settings['hover_action_column_key']][0];
					} else {
						$hover_action_column_value = $item[$settings['hover_action_column_key']];
					}
				} else {
					$hover_action_column_value = '';
				}
				if ( strstr( $action_slug, '/' ) === false ) { 
					$hover_link= pb_backupbuddy::page_url() . '&' . $action_slug . '=' . $item_id . '&value=' . $hover_action_column_value;
				} else { 
					$hover_link = $action_slug . $hover_action_column_value;
				}
				if ( '.zip' == substr( $hover_link, -4 ) ) {
					$hover_link .= '&bub_rand=' . rand( 100, 999 );
				}
				echo '<a href="' . $hover_link . '" class="pb_' . pb_backupbuddy::settings( 'slug' ) . '_hoveraction_' . $action_slug . '" rel="' . $hover_action_column_value . '">' . $action_title . '</a>';
				if ( $i < count( $settings['hover_actions'] ) ) {
					echo ' | ';
				}
			}
			echo '			</div>
						</td>';
			if ( $settings['reorder'] != '' ) {
				$count = count( $item ) + 1; 
			} else {
				$count = count( $item );
			}
			for ( $i = 1; $i < $count; $i++ ) {
				if ( ! isset( $item[$i] ) ) { continue; } 				echo '<td';
				if ( $settings['reorder'] != '' ) {
					if ( $i == $settings['reorder'] ) {
						echo ' class="pb_draghandle" align="center"';
					}
				}
				echo '>';
				if ( ( $settings['reorder'] != '' ) && ( $i == ( $settings['reorder'] ) ) ) {
					echo '<img src="' . pb_backupbuddy::plugin_url() . '/pluginbuddy/images/draghandle.png" alt="Click and drag to reorder">';
				} else {
					if ( $item[$i] == '' ) {
						echo '&nbsp;';
					} else {
						echo $item[$i];
					}
				}
				echo '</td>';
			}
			echo '	</tr>';
		}
		echo '	</tbody>';
		echo '</table>';
		bulk_actions( $settings, true );
		echo '</div>';
		if ( $settings['action'] != '' ) {
			echo '</form>';
		}
	}
public static function list_table ( $ items , $ settings ) { $ default_settings = array ( 'columns' => array ( ) , 'hover_actions' => array ( ) , 'bulk_actions' => array ( ) , 'hover_action_column_key' => '' , 'action' => '' , 'reorder' => '' , 'after_bulk' => '' , 'css' => '' , ) ; $ settings = array_merge ( $ default_settings , $ settings ) ; if ( ! function_exists ( 'bulk_actions' ) ) { function bulk_actions ( $ settings , $ hover_note = false ) { if ( count ( $ settings [ 'bulk_actions' ] ) > 0 ) { echo '<div style="padding-bottom: 3px; padding-top: 3px;">' ; if ( count ( $ settings [ 'bulk_actions' ] ) == 1 ) { foreach ( $ settings [ 'bulk_actions' ] as $ action_slug => $ action_title ) { echo '<input type="hidden" name="bulk_action" value="' . $ action_slug . '">' ; echo '<input type="submit" name="do_bulk_action" value="' . $ action_title . '" class="button secondary-button backupbuddy-do_bulk_action">' ; } } else { echo '<select name="bulk_action" class="actions">' ; foreach ( $ settings [ 'bulk_actions' ] as $ action_slug => $ action_title ) { echo '<option>Bulk Actions</option>' ; echo '<option value="' . $ action_slug . '">' . $ action_title . '</option>' ; } echo '</select> &nbsp;' ; echo '<input type="submit" name="do_bulk_action" value="Apply" class="button secondary-button backupbuddy-do_bulk_action">' ; } echo '&nbsp;&nbsp;' ; echo $ settings [ 'after_bulk' ] ; echo '<div class="alignright actions">' ; if ( $ hover_note === true ) { echo pb_backupbuddy :: $ ui -> note ( 'Hover over items above for additional options.' ) ; } if ( $ settings [ 'reorder' ] != '' ) { echo '	<input type="submit" name="save_order" id="save_order" value="Save Order" class="button-secondary" />' ; } echo '</div>' ; echo '</div>' ; } } } if ( $ settings [ 'action' ] != '' ) { echo '<form method="post" action="' . $ settings [ 'action' ] . '">' ; pb_backupbuddy :: nonce ( ) ; if ( $ settings [ 'reorder' ] != '' ) { echo '<input type="hidden" name="order" value="" id="pb_order">' ; } } echo '<div style="width: 70%; min-width: 720px; ' . $ settings [ 'css' ] . '">' ; bulk_actions ( $ settings ) ; echo '<table class="widefat striped"' ; echo ' id="test">' ; echo '		<thead>
					<tr class="thead">' ; if ( count ( $ settings [ 'bulk_actions' ] ) > 0 ) { echo '		<th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>' ; } foreach ( $ settings [ 'columns' ] as $ column ) { echo '<th>' . $ column . '</th>' ; } echo '		</tr>
				</thead>
			<tfoot>
				<tr class="thead">' ; if ( count ( $ settings [ 'bulk_actions' ] ) > 0 ) { echo '	<th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>' ; } foreach ( $ settings [ 'columns' ] as $ column ) { echo '<th>' . $ column . '</th>' ; } echo '	</tr>
			</tfoot>
			<tbody' ; if ( $ settings [ 'reorder' ] != '' ) { echo ' class="pb_reorder"' ; } echo '>' ; foreach ( ( array ) $ items as $ item_id => $ item ) { echo '	<tr class="entry-row" id="pb_rowitem-' . $ item_id . '">' ; if ( count ( $ settings [ 'bulk_actions' ] ) > 0 ) { echo '	<th scope="row" class="check-column"><input type="checkbox" name="items[]" class="entries" value="' . $ item_id . '"></th>' ; } echo '		<td>' ; if ( is_array ( $ item [ '0' ] ) ) { if ( $ item [ '0' ] [ 1 ] == '' ) { echo '&nbsp;' ; } else { echo $ item [ '0' ] [ 1 ] ; } } else { if ( $ item [ '0' ] == '' ) { echo '&nbsp;' ; } else { echo $ item [ '0' ] ; } } echo '			<div class="row-actions" style="margin-top: 10px;">' ; $ i = 0 ; foreach ( $ settings [ 'hover_actions' ] as $ action_slug => $ action_title ) { $ i ++ ; if ( $ settings [ 'hover_action_column_key' ] != '' ) { if ( is_array ( $ item [ $ settings [ 'hover_action_column_key' ] ] ) ) { $ hover_action_column_value = $ item [ $ settings [ 'hover_action_column_key' ] ] [ 0 ] ; } else { $ hover_action_column_value = $ item [ $ settings [ 'hover_action_column_key' ] ] ; } } else { $ hover_action_column_value = '' ; } if ( strstr ( $ action_slug , '/' ) === false ) { $ hover_link = pb_backupbuddy :: page_url ( ) . '&' . $ action_slug . '=' . $ item_id . '&value=' . $ hover_action_column_value ; } else { $ hover_link = $ action_slug . $ hover_action_column_value ; } if ( '.zip' == substr ( $ hover_link , - 4 ) ) { $ hover_link .= '&bub_rand=' . rand ( 100 , 999 ) ; } echo '<a href="' . $ hover_link . '" class="pb_' . pb_backupbuddy :: settings ( 'slug' ) . '_hoveraction_' . $ action_slug . '" rel="' . $ hover_action_column_value . '">' . $ action_title . '</a>' ; if ( $ i < count ( $ settings [ 'hover_actions' ] ) ) { echo ' | ' ; } } echo '			</div>
						</td>' ; if ( $ settings [ 'reorder' ] != '' ) { $ count = count ( $ item ) + 1 ; } else { $ count = count ( $ item ) ; } for ( $ i = 1 ; $ i < $ count ; $ i ++ ) { if ( ! isset ( $ item [ $ i ] ) ) { continue ; } echo '<td' ; if ( $ settings [ 'reorder' ] != '' ) { if ( $ i == $ settings [ 'reorder' ] ) { echo ' class="pb_draghandle" align="center"' ; } } echo '>' ; if ( ( $ settings [ 'reorder' ] != '' ) && ( $ i == ( $ settings [ 'reorder' ] ) ) ) { echo '<img src="' . pb_backupbuddy :: plugin_url ( ) . '/pluginbuddy/images/draghandle.png" alt="Click and drag to reorder">' ; } else { if ( $ item [ $ i ] == '' ) { echo '&nbsp;' ; } else { echo $ item [ $ i ] ; } } echo '</td>' ; } echo '	</tr>' ; } echo '	</tbody>' ; echo '</table>' ; bulk_actions ( $ settings , true ) ; echo '</div>' ; if ( $ settings [ 'action' ] != '' ) { echo '</form>' ; } }
pluginbuddy_ui->list_table()
pluginbuddy_ui - > list_table ()
// int of column to set value= in URL and rel tag= for using in JS. // Merge defaults. // Function to iterate through bulk actions. Top and bottom set are the same. //echo self::button( '#', 'Apply' ); // End subfunction bulk_actions(). // End if function does not exist. // Display bulk actions (top). // LOOP THROUGH EACH ROW. //  style="margin:0; padding:0;" // Display all hover actions. //echo 'slug: ' . $action_slug; // Word hover action slug. // URL hover action slug so just append value to URL. // Some host's don't allow get params that end in .zip // Extra row for reordering. // LOOP THROUGH COLUMNS FOR THIS ROW. // This row does not have a corresponding index-based item.  It is probably a named key not for use in table?
 // Display bulk actions (bottom).