From 235f810dd3976197b5d1ba4ef64a39361a8986b5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 27 Nov 2012 09:34:38 -0500 Subject: [PATCH] Miscellaneous fixes and updates Change php requirement to 5.4 --- OpenSQLManager.php | 21 +++++++++---- README.md | 3 +- resources/LICENSE | 18 ++++++------ sys/common/functions.php | 2 +- sys/common/settings.php | 11 +++++-- sys/widgets/connection_sidebar.php | 47 ++++++++++++++++++------------ sys/windows/connection_manager.php | 14 ++++++++- sys/windows/main.php | 15 ++++++++-- 8 files changed, 89 insertions(+), 42 deletions(-) diff --git a/OpenSQLManager.php b/OpenSQLManager.php index 261c491..b6cf0cf 100644 --- a/OpenSQLManager.php +++ b/OpenSQLManager.php @@ -48,7 +48,7 @@ function log_fatal() $error = error_get_last(); // types of errors that are fatal - $fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR); + $fatal = [E_ERROR, E_PARSE, E_RECOVERABLE_ERROR]; // Log error. if(in_array($error['type'], $fatal)) @@ -61,11 +61,20 @@ register_shutdown_function('OpenSQLManager\log_fatal'); // -------------------------------------------------------------------------- -// Make sure php-gtk works +// Make sure wxphp works if ( ! class_exists('wxApp')) { - trigger_error("wxPHP not found. Please load the wxPHP extension in your php.ini", E_USER_ERROR); - die(); + // Try to load wxphp if possible + if (function_exists('dl') && in_array(php_sapi_name(), ['cli', 'embed'])) + { + $name = 'wxwidgets.'.PHP_SHLIB_SUFFIX; + dl($name); + } + else + { + trigger_error("wxPHP not found. Please load the wxPHP extension in your php.ini", E_USER_ERROR); + die(); + } } // Make sure pdo exists @@ -93,7 +102,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline) // Do this after the two compatibility checks for cleaner output // Note that this will throw exceptions on notices -set_error_handler("OpenSQLManager\exception_error_handler", -1); +set_error_handler('OpenSQLManager\exception_error_handler', -1); // -------------------------------------------------------------------------- @@ -138,7 +147,7 @@ function osm_autoload($class) // -------------------------------------------------------------------------- -// Load everything so that we don't have to do requires later +// Load all the common classes, and register the autoloader array_map('OpenSQLManager\do_include', glob(BASE_DIR.'/common/*.php')); spl_autoload_register('OpenSQLManager\osm_autoload'); diff --git a/README.md b/README.md index c4378f6..fdf6f9f 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,11 @@ I've put together this package from the latest wxPHP windows package. It's avail * php5-postgresql * php5-sqlite * php5-ssh2 + * Compile wxPHP extension * Run via terminal in the OpenSQLManager folder using `php OpenSQLManager.php` ## PHP Requirements -* Version 5.3.* +* Version 5.4+ * [wxPHP](http://wxphp.org/) PHP Extension * OpenSSL * JSON diff --git a/resources/LICENSE b/resources/LICENSE index 2c0bb65..1ac001a 100644 --- a/resources/LICENSE +++ b/resources/LICENSE @@ -1,6 +1,6 @@ -DON'T BE A DICK PUBLIC LICENSE +DON'T BE A JERK PUBLIC LICENSE - Version 1, December 2009 + Version 2, November 2012 Copyright (C) 2012 Timothy J Warren @@ -8,20 +8,20 @@ DON'T BE A DICK PUBLIC LICENSE copies of this license document, and changing it is allowed as long as the name is changed. - DON'T BE A DICK PUBLIC LICENSE + DON'T BE A JERK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 1. Do whatever you like with the original work, just don't be a dick. + 1. Do whatever you like with the original work, just don't be a JERK. - Being a dick includes - but is not limited to - the following instances: + Being a JERK includes - but is not limited to - the following instances: 1a. Outright copyright infringement - Don't just copy this and change the name. - 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. - 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. + 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a JERK. + 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER JERK. 2. If you become rich through modifications, related works/services, or supporting the original work, - share the love. Only a dick would make loads off this work and not buy the original works + share the love. Only a JERK would make loads off this work and not buy the original works creator(s) a pint. 3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes - you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. \ No newline at end of file + you a DONKEY JERK. Fix the problem yourself. A non-JERK would submit the fix back. \ No newline at end of file diff --git a/sys/common/functions.php b/sys/common/functions.php index fb7be5e..8b36a6f 100644 --- a/sys/common/functions.php +++ b/sys/common/functions.php @@ -37,7 +37,7 @@ function array_to_object($array) $obj = new \StdClass(); - foreach($array as $k => &$v) + foreach($array as $k => $v) { $obj->$k = $v; } diff --git a/sys/common/settings.php b/sys/common/settings.php index b0026c1..1fa9807 100644 --- a/sys/common/settings.php +++ b/sys/common/settings.php @@ -68,12 +68,19 @@ class Settings { if( ! is_file($path)) { //Create the file! - touch($path); + file_put_contents($path, '{}'); $this->current = new \stdClass(); } else { $this->current = json_decode(file_get_contents($path)); + + if (empty($this->current)) + { + $this->current = new \stdClass(); + file_put_contents($path, '{}'); + } + } // Add the DB object under the settings if it doesn't already exist @@ -179,7 +186,7 @@ class Settings { { return FALSE; } - + if (is_object($params)) { $params = (array) $params; diff --git a/sys/widgets/connection_sidebar.php b/sys/widgets/connection_sidebar.php index 75c010f..96dc38c 100644 --- a/sys/widgets/connection_sidebar.php +++ b/sys/widgets/connection_sidebar.php @@ -63,6 +63,13 @@ class Connection_Sidebar extends \wxPanel { * @var wxListCtrl */ private $list; + + /** + * Reference to the parent of the current object + * + * @var object + */ + public $parent; /** * Return the current instance of the class @@ -90,28 +97,13 @@ class Connection_Sidebar extends \wxPanel { */ public function __construct($parent) { + $this->parent =& $parent; + // Create the frame parent::__construct($parent, 1); - $this->list = new \wxListCtrl($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL); - $this->settings =& Settings::get_instance(); - $this->list->Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, array($this, 'menu')); - - // Create a button for adding new connections - $new_conn = new \wxButton($this, self::BTN_ADD, 'New Connection'); - $new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn')); - // Layout the connection list $this->_layout(); - - // Add a sizer - $sizer = new \wxBoxSizer(wxVERTICAL); - $sizer->add($this->list, 1, wxALL|wxEXPAND); - $sizer->add($new_conn, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM|wxEXPAND, 5); - - $this->SetSizer($sizer); - $this->Layout(); - $this->Fit(); } // -------------------------------------------------------------------------- @@ -187,8 +179,16 @@ class Connection_Sidebar extends \wxPanel { * * @return void */ - private function _layout() - { + public function _layout() + { + $this->list = new \wxListCtrl($this->parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL); + $this->settings =& Settings::get_instance(); + $this->list->Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, array($this, 'menu')); + + // Create a button for adding new connections + $new_conn = new \wxButton($this, self::BTN_ADD, 'New Connection'); + $new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn')); + // Add the actual connections $conns = $this->settings->get_dbs(); @@ -196,6 +196,15 @@ class Connection_Sidebar extends \wxPanel { { $this->list->InsertItem(0, $c->name); } + + // Add a sizer + $sizer = new \wxBoxSizer(wxVERTICAL); + $sizer->add($this->list, 1, wxALL|wxEXPAND); + $sizer->add($new_conn, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM|wxEXPAND, 5); + + $this->SetSizer($sizer); + $this->Layout(); + $this->Fit(); } } diff --git a/sys/windows/connection_manager.php b/sys/windows/connection_manager.php index 97c8b59..167713c 100644 --- a/sys/windows/connection_manager.php +++ b/sys/windows/connection_manager.php @@ -47,6 +47,13 @@ class Connection_Manager extends \wxFrame { * @var array */ protected $labels = array(); + + /** + * Reference to the parent Control + * + * @var object + */ + protected $parent; /** * Create the window @@ -56,6 +63,7 @@ class Connection_Manager extends \wxFrame { */ public function __construct($parent, $params = array()) { + $this->parent =& $parent; parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxSTAY_ON_TOP | wxRESIZE_BORDER); // Save a reference to the settings class @@ -213,6 +221,10 @@ class Connection_Manager extends \wxFrame { } $this->settings->add_db($params->name, $params); + + $this->parent->Update(); + + $this->Destroy(); } // -------------------------------------------------------------------------- @@ -314,7 +326,7 @@ class Connection_Manager extends \wxFrame { { \Query($params); } - catch (\PDOException $e) + catch (\Exception $e) { error("Error connecting to database: \n\n" . $e->getMessage()); return; diff --git a/sys/windows/main.php b/sys/windows/main.php index b5cbae3..d76f34a 100644 --- a/sys/windows/main.php +++ b/sys/windows/main.php @@ -85,7 +85,7 @@ class Main extends \wxFrame { */ public function quit() { - $this->Destroy(); + $this->__destruct(); } // -------------------------------------------------------------------------- @@ -95,7 +95,7 @@ class Main extends \wxFrame { * * @return void */ - function about() + public function about() { $dlg = new \wxAboutDialogInfo(); @@ -115,6 +115,16 @@ class Main extends \wxFrame { \wxAboutBox($dlg); } + // -------------------------------------------------------------------------- + + /** + * Layout tabs for databases, tables, &c; + */ + public function load_tabs() + { + + } + // -------------------------------------------------------------------------- /** @@ -181,7 +191,6 @@ class Main extends \wxFrame { } - $this->SetMenuBar($menu_bar); } }