Skip to content

Commit

Permalink
CS fixes, and sorting working again.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Feb 2, 2016
1 parent d3890b8 commit c9b4c7b
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 64 deletions.
2 changes: 1 addition & 1 deletion assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ form.tabulate-record .point-column .map { width:450px; height:200px; border:1px

table.tabulate.widefat th,
table.tabulate.widefat td { padding:0.25em }
table.tabulate.widefat thead th .sort-icons a { visibility:hidden }
table.tabulate.widefat thead th .sort-icons a { visibility:hidden; padding:0; display:inline }
table.tabulate.widefat thead th.sortable:hover { background-color:#deedee }
table.tabulate.widefat thead th.sortable:hover .sort-icons a { visibility:visible }
table.tabulate.widefat td { line-height:1em }
Expand Down
2 changes: 1 addition & 1 deletion src/DB/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function get_order_by() {
* @param string $order_by The name of the column to order by.
*/
public function set_order_by( $order_by ) {
if ( in_array( $order_by, array_keys( $this->columns ) ) ) {
if ( $this->get_column( $order_by ) ) {
$this->order_by = $order_by;
}
}
Expand Down
40 changes: 25 additions & 15 deletions src/Menus.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
<?php
/**
* This file contains only the Menus class
*
* @package WordPress
* @subpackage Tabulate
*/

namespace WordPress\Tabulate;

/**
* This class is an attempt to group all functionality around managing the menus
* in the Admin Area in one place. It includes adding scripts and stylesheets.
*/
class Menus {

/**
* The global wpdb object.
* @var \wpdb
*/
protected $wpdb;

/**
* The page output is stored between being called/created in
* self::dispatch() and output in self::add_menu_pages()
*
* @var string
*/
protected $output;

public function __construct($wpdb) {
/**
* Create a new Menus object, supplying it with the database so that it
* doesn't have to use a global.
* @param \wpdb $wpdb The global wpdb object.
*/
public function __construct( $wpdb ) {
$this->wpdb = $wpdb;
}

/**
* Set up all required hooks.
*
* This is called from the top level of tabulate.php
* Set up all required hooks. This is called from the top level of tabulate.php
* @return void
*/
public function init() {
Expand Down Expand Up @@ -79,10 +92,7 @@ public function admin_bar_menu() {
}

/**
* Get any currently-stored output. This is the callback for all the menu
* items.
*
* @return string The page HTML.
* Print the currently-stored output; this is the callback for all the menu items.
*/
public function output() {
echo $this->output;
Expand All @@ -99,7 +109,7 @@ public function dispatch() {

// Only dispatch when it's our page.
$slugLenth = strlen( TABULATE_SLUG );
if ( ! isset( $request['page'] ) || substr( $request['page'], 0, $slugLenth ) != TABULATE_SLUG ) {
if ( ! isset( $request['page'] ) || substr( $request['page'], 0, $slugLenth ) !== TABULATE_SLUG ) {
return;
}

Expand All @@ -115,8 +125,8 @@ public function dispatch() {
// Create the controller and run the action.
$controllerClassName = 'WordPress\\Tabulate\\Controllers\\' . ucfirst( $controllerName ) . 'Controller';
$controller = new $controllerClassName( $this->wpdb );
$action = ! empty( $request[ 'action' ] ) ? $request[ 'action' ] : 'index';
unset( $request[ 'page' ], $request[ 'controller' ], $request[ 'action' ] );
$action = ! empty( $request['action'] ) ? $request['action'] : 'index';
unset( $request['page'], $request['controller'], $request['action'] );
try {
$this->output = $controller->$action( $request );
} catch ( \Exception $e ) {
Expand All @@ -128,13 +138,14 @@ public function dispatch() {
* This is the callback method used in self::init() to add scripts and
* styles to the Tabulate admin pages and everywhere the shortcode is used.
*
* @param string $page The current page name.
* @return void
*/
public function enqueue( $page ) {
// Make sure we only enqueue on Tabulate pages.
$allowed_pages = array(
'index.php', // For the Dashboard widget.
'tabulate_shortcode', // Not really a page! :-(
'tabulate_shortcode', // Not really a page.
'toplevel_page_tabulate',
'tabulate_page_tabulate_erd',
'tabulate_page_tabulate_reports',
Expand Down Expand Up @@ -165,7 +176,7 @@ public function enqueue( $page ) {

// Javascript page variables.
$js_vars = array(
'admin_url' => admin_url() . 'admin.php?page=' . TABULATE_SLUG
'admin_url' => admin_url() . 'admin.php?page=' . TABULATE_SLUG,
);
wp_localize_script( 'tabulate-scripts', 'tabulate', $js_vars );

Expand All @@ -181,5 +192,4 @@ public function enqueue( $page ) {
$style_url = plugins_url( TABULATE_SLUG ) . '/assets/style.css';
wp_enqueue_style( 'tabulate-styles', $style_url, null, TABULATE_VERSION );
}

}
54 changes: 43 additions & 11 deletions src/Template.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
<?php
/**
* This file contains only the Text class
*
* @package WordPress
* @subpackage Tabulate
*/

namespace WordPress\Tabulate;

/**
* A Template is a wrapper for a Twig file
*/
class Template {

/** @var string */
/**
* The name of the template to render (if not using a Twig string).
* @var string
*/
protected $template_name;

/** @var string */
/**
* The Twig string to render (if not using a template file).
* @var string
*/
protected $template_string;

/** @var string[] */
/**
* The template data, all of which is passed to the Twig template.
* @var string[]
*/
protected $data;

/** @var string[] Paths at which to find templates. */
/**
* Paths at which to find templates.
* @var string[]
*/
protected static $paths = array();

/** @var string The name of the transient used to store notices. */
/**
* The name of the transient used to store notices.
* @var string
*/
protected $transient_notices;

/**
* Create a new template either with a file-based Twig template, or a Twig string.
* @global type $wpdb
* @param string|false $template_name
* @param string|false $template_string
* @param string|false $template_name The name of a Twig file to render.
* @param string|false $template_string A Twig string to render.
*/
public function __construct( $template_name = false, $template_string = false ) {
global $wpdb;
Expand All @@ -47,7 +71,7 @@ public function __construct( $template_name = false, $template_string = false )

/**
* Add a filesystem path under which to look for template files.
* @param string $new_path
* @param string $new_path The path to add.
*/
public static function add_path( $new_path ) {
$path = realpath( $new_path );
Expand All @@ -56,13 +80,17 @@ public static function add_path( $new_path ) {
}
}

/**
* Get a list of the filesystem paths searched for template files.
* @return string[] An array of paths
*/
public static function get_paths() {
return self::$paths;
}

/**
* Get a list of templates in a given directory, across all registered template paths.
* @param string $directory
* @param string $directory The directory to search in.
*/
public function get_templates( $directory ) {
$templates = array();
Expand All @@ -75,6 +103,11 @@ public function get_templates( $directory ) {
return $templates;
}

/**
* Magically set a template variable.
* @param string $name The name of the variable.
* @param mixed $value The value of the variable.
*/
public function __set( $name, $value ) {
$this->data[ $name ] = $value;
}
Expand All @@ -92,7 +125,7 @@ public function __isset( $name ) {
/**
* Get an item from this template's data.
*
* @param string $name
* @param string $name The name of the template variable.
* @return mixed
*/
public function __get( $name ) {
Expand Down Expand Up @@ -172,5 +205,4 @@ public function render() {
}
return $template->render( $this->data );
}

}
28 changes: 18 additions & 10 deletions src/Text.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?php
/**
* This file contains only the Text class
*
* @package WordPress
* @subpackage Tabulate
*/

namespace WordPress\Tabulate;

/**
* The Text class contains static methods for working with text
*/
class Text {

/**
* Turn a spaced or underscored string to camelcase (with no spaces or underscores).
*
* @param string $str
* @param string $str The string to format.
* @return string
*/
public static function camelcase($str) {
public static function camelcase( $str ) {
return str_replace( ' ', '', ucwords( str_replace( '_', ' ', $str ) ) );
}

Expand All @@ -19,13 +28,13 @@ public static function camelcase($str) {
* initial letters, and performing a few common (and not-so-common) word
* replacements such as initialisms and punctuation.
*
* @param string|array $value The underscored and lowercase string to be
* titlecased, or an array of such strings.
* @param string|array $value The underscored and lowercase string to be titlecased, or an array of such strings.
* @param 'html'|'latex' $format The desired output format.
* @return string A properly-typeset title.
*
* @return string A properly-typeset title.
* @todo Get replacement strings from configuration file.
*/
public static function titlecase($value, $format = 'html') {
public static function titlecase( $value, $format = 'html' ) {

/**
* The mapping of words (and initialisms, etc.) to their titlecased
Expand Down Expand Up @@ -55,7 +64,7 @@ public static function titlecase($value, $format = 'html') {
/**
* Marshall the correct replacement strings.
*/
if ( 'latex' == $format ) {
if ( 'latex' === $format ) {
$replacements = array_merge( $html_replacements, $latex_replacements );
} else {
$replacements = $html_replacements;
Expand All @@ -77,7 +86,7 @@ public static function titlecase($value, $format = 'html') {

/**
* Format a MySQL-format date according to WP's preference.
* @param string $date
* @param string $date The date string to format.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
public static function wp_date_format( $date ) {
Expand All @@ -86,11 +95,10 @@ public static function wp_date_format( $date ) {

/**
* Format a MySQL-format time according to WP's preference.
* @param string $time
* @param string $time The time string to format.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
public static function wp_time_format( $time ) {
return mysql2date( get_option( 'time_format' ), $time );
}

}
57 changes: 33 additions & 24 deletions src/Util.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<?php

namespace WordPress\Tabulate;

class Util {

/**
* Check whether the plugin is active by checking the active_plugins list.
*
* This is an duplicate of the function defined in wp-adin/includes/plugin.php
* It's redefined here so we can use it in the frontend without including
* all of the plugin.php file.
*
* @param string $plugin Base plugin path from plugins directory.
* @return bool True, if in the active plugins list. False, not in the list.
*/
public static function is_plugin_active( $plugin ) {
if ( function_exists( 'is_plugin_active' ) ) {
return is_plugin_active( $plugin );
}
return in_array( $plugin, get_option( 'active_plugins', array() ) );
}

}
<?php
/**
* This file contains only the Util class
*
* @package WordPress
* @subpackage Tabulate
*/

namespace WordPress\Tabulate;

/**
* This is a utility class to hold miscellaneous helper methods.
* Not great design, certainly, but then neither is lots of WP core.
*/
class Util {

/**
* Check whether the plugin is active by checking the active_plugins list.
*
* This is an duplicate of the function defined in wp-adin/includes/plugin.php
* It's redefined here so we can use it in the frontend without including
* all of the plugin.php file.
*
* @param string $plugin Base plugin path from plugins directory.
* @return bool True, if in the active plugins list. False, not in the list.
*/
public static function is_plugin_active( $plugin ) {
if ( function_exists( 'is_plugin_active' ) ) {
return is_plugin_active( $plugin );
}
return in_array( $plugin, get_option( 'active_plugins', array() ) );
}
}
4 changes: 2 additions & 2 deletions tabulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* License: GPL-2.0+
* Text Domain: tabulate
* Domain Path: /languages
* Version: 2.6.0
* Version: 2.6.1
*/
define( 'TABULATE_VERSION', '2.6.0' );
define( 'TABULATE_VERSION', '2.6.1' );
define( 'TABULATE_SLUG', 'tabulate' );

// Load textdomain.
Expand Down

0 comments on commit c9b4c7b

Please sign in to comment.