Implemented namespace for this plugin and fixed issues resulting from that.
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 2 Oct 2019 19:24:53 +0000 (15:24 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 16 Oct 2019 13:19:02 +0000 (09:19 -0400)
24 files changed:
activate.php
classes/GlmServerStats.php
classes/serverBandwidthSupport.php
deactivate.php
defines.php
index.php
lib/opentools-update-checker/opentools-update-checker.php
lib/plugin-update-checker/debug-bar-panel.php
lib/plugin-update-checker/debug-bar-plugin.php
lib/plugin-update-checker/github-checker.php
lib/plugin-update-checker/plugin-update-checker.php
lib/plugin-update-checker/vendor/readme-parser.php
lib/smartyTemplateSupport.php
models/adminServerStats.php
models/ajaxSendUsageReport.php
models/ajaxServerBandwidthGraphs.php
models/frontCookiePopUp.php
models/glmInfoNotifications.php
models/serverUsageTargetCheck.php
setup/adminHooks.php
setup/adminMenus.php
setup/commonHooks.php
setup/standardTemplateParams.php
uninstall.php

index e89aff1..5ebcba6 100755 (executable)
@@ -1,5 +1,5 @@
 <?php
-
+namespace GLMServerStats;
 /**
  * Gaslight Media ServerStats - Stand Alone
  * Activate Plugin Tasks
@@ -97,7 +97,7 @@ class glmServerStatsPluginActivate
             }
 
         } else {
-            trigger_error("*** SLUG FOUND ***",E_USER_NOTICE);
+            trigger_error("glm-serverstats: Policy page already exists on activation.",E_USER_NOTICE);
         }
 
     }
index 31c0862..1915799 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * database.php
  *
@@ -136,7 +137,7 @@ class GlmServerStats
     public function updateCache()
     {
         // Prevent this from running on activation of this plugin.
-        if ( class_exists( 'glmServerStatsPluginActivate' ) ) {
+        if ( class_exists( 'GLMServerStats\glmServerStatsPluginActivate' ) ) {
             return false;
         }
         // If the update transient exists don't get anything from the relay.
index b3f9613..b259628 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media Server Bandwidth - Stand Alone
  * Server Bandwidth Support Abstract
index 93f26e7..852ea51 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media ServerStats - Stand Alone
  * Deactivate Plugin Tasks
index 20f6e38..450b3fd 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media ServerStats - Stand Alone
  *
index 1f82c74..36b0984 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Plugin Name: GLM Bandwidth
  * Plugin URI: http://www.gaslightmedia.com/
@@ -53,8 +54,9 @@ $websiteSettings = bandwidthDataConnect(GLM_SERVERSTATS_PLUGIN_HOSTNAME);
 
 // If this is an admin request
 if (is_admin()) {
-    add_action('admin_menu', 'configureMenus');
-    require_once GLM_SERVERSTATS_PLUGIN_PATH.'/setup/adminHooks.php';
+    add_action('admin_menu', function() {
+        require_once GLM_SERVERSTATS_PLUGIN_PATH.'/setup/adminMenus.php';
+    });
 }
 
 // If setup/commonHooks.php exists include that now
@@ -63,18 +65,10 @@ if ( is_file( $commonFile ) ) {
     require_once $commonFile;
 }
 
-/*
- * Function to configure admin menus
- */
-function configureMenus ()
-{
-    require_once GLM_SERVERSTATS_PLUGIN_PATH.'/setup/adminMenus.php';
-}
-
 /*
  * Setup AJAX
  */
-add_action( 'wp_ajax_glm_server_stats', 'glmServerStatsAjax');
+add_action( 'wp_ajax_glm_server_stats', '\GLMServerStats\glmServerStatsAjax');
 
 /*
  *
@@ -175,13 +169,13 @@ if ( ( !empty( $_REQUEST['force_cookie'] ) || $websiteSettings['show_cookie_popu
     function enqueueJquery() {
         glmServerJqueryScipts();
     }
-    add_action( 'wp_enqueue_scripts', 'enqueueJquery' );
+    add_action( 'wp_enqueue_scripts', '\GLMServerStats\enqueueJquery' );
 
     // Have WordPress include the cookie pop-up code just before the footer.
     function doCookiePopUp() {
         include GLM_SERVERSTATS_PLUGIN_MODEL_PATH . '/frontCookiePopUp.php';
     }
-    add_action( 'wp_footer', 'doCookiePopUp' );
+    add_action( 'get_footer', '\GlmServerStats\doCookiePopUp' );
 
 }
 
@@ -224,6 +218,8 @@ function glmServerStatsAjax()
 function serverStatsController( $model, $isAjax = false )
 {
 
+    $namespaceModel = '\\GLMServerStats\\'.$model;
+
     if ( GLM_SERVERSTATS_PLUGIN_DEBUG ) {
         $debugStartTime = microtime( true );
         trigger_error("GLM Usage Controller Start: Model = $model", E_USER_NOTICE );
@@ -239,7 +235,7 @@ function serverStatsController( $model, $isAjax = false )
 
     // Load and execute the specified model
     require_once GLM_SERVERSTATS_PLUGIN_MODEL_PATH . '/' . $model . '.php';
-    $Model   = new $model();
+    $Model   = new $namespaceModel();
     $results = $Model->model();
 
     // If there's a redirect request, run that (this controler can only do one level of redirect)
@@ -305,7 +301,7 @@ function glmServerStatsPluginActivate ()
     require_once GLM_SERVERSTATS_PLUGIN_PATH . '/activate.php';
     new glmServerStatsPluginActivate();
 }
-register_activation_hook(__FILE__, 'glmServerStatsPluginActivate');
+register_activation_hook(__FILE__, '\GLMServerStats\glmServerStatsPluginActivate');
 
 // Deactivate
 function glmServerStatsPluginDeactivate ()
@@ -314,7 +310,7 @@ function glmServerStatsPluginDeactivate ()
     $x = new glmServerStatsPluginDeactivate();
     return false;
 }
-register_deactivation_hook(__FILE__, 'glmServerStatsPluginDeactivate');
+register_deactivation_hook(__FILE__, '\GLMServerStats\glmServerStatsPluginDeactivate');
 
 /*
  * Check if we should run the target check E-mail process
@@ -369,7 +365,7 @@ function doGlmServerUsageCron() {
     }
 
 }
-add_action('glm_serverstats_notify_cron', 'doGlmServerUsageCron');
+add_action('glm_serverstats_notify_cron', '\GLMServerStats\doGlmServerUsageCron');
 
 /*
  * This code sets up a once per minute cron schedule to use for testing.
index 6f0b4bb..2cee653 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * OpenTools Plugin Update Checker Library
  *
@@ -13,7 +14,7 @@
 // * http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/
 // *****************************************************************
 
-if (!class_exists('OpenToolsPluginUpdateChecker')):
+if (!class_exists('GLMServerStats\OpenToolsPluginUpdateChecker')):
 
 require dirname(__FILE__).'/../plugin-update-checker/plugin-update-checker.php';
 
index 40be65a..0c07f27 100644 (file)
@@ -1,6 +1,6 @@
 <?php
-
-if ( !class_exists('PluginUpdateCheckerPanel_3_1', false) && class_exists('Debug_Bar_Panel', false) ) {
+namespace GLMServerStats;
+if ( !class_exists('GLMServerStats\PluginUpdateCheckerPanel_3_1', false) && class_exists('GLMServerStats\Debug_Bar_Panel', false) ) {
 
 /**
  * A Debug Bar panel for the plugin update checker.
index fdfb918..a8bc8ce 100644 (file)
@@ -1,5 +1,6 @@
 <?php
-if ( !class_exists('PucDebugBarPlugin_3_1', false) ) {
+namespace GLMServerStats;
+if ( !class_exists('GLMServerStats\PucDebugBarPlugin_3_1', false) ) {
 
 class PucDebugBarPlugin_3_1 {
        /** @var PluginUpdateChecker_3_1 */
@@ -23,7 +24,7 @@ class PucDebugBarPlugin_3_1 {
         */
        public function addDebugBarPanel($panels) {
                require_once dirname(__FILE__) . '/debug-bar-panel.php';
-               if ( current_user_can('update_plugins') && class_exists('PluginUpdateCheckerPanel_3_1', false) ) {
+               if ( current_user_can('update_plugins') && class_exists('GLMServerStats\PluginUpdateCheckerPanel_3_1', false) ) {
                        $panels[] = new PluginUpdateCheckerPanel_3_1($this->updateChecker);
                }
                return $panels;
index 7867fe6..c2d506f 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
-\r
-if ( !class_exists('PucGitHubChecker_3_1', false) ):\r
+namespace GLMServerStats;\r
+if ( !class_exists('GLMServerStats\PucGitHubChecker_3_1', false) ):\r
 \r
 class PucGitHubChecker_3_1 extends PluginUpdateChecker_3_1 {\r
        /**\r
@@ -238,7 +238,7 @@ class PucGitHubChecker_3_1 extends PluginUpdateChecker_3_1 {
         * @return string\r
         */\r
        protected function parseMarkdown($markdown) {\r
-               if ( !class_exists('Parsedown', false) ) {\r
+               if ( !class_exists('GLMServerStats\Parsedown', false) ) {\r
                        require_once(dirname(__FILE__) . '/vendor/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');\r
                }\r
 \r
@@ -416,7 +416,7 @@ class PucGitHubChecker_3_1 extends PluginUpdateChecker_3_1 {
        }\r
 \r
        protected function parseReadme($content) {\r
-               if ( !class_exists('PucReadmeParser', false) ) {\r
+               if ( !class_exists('GLMServerStats\PucReadmeParser', false) ) {\r
                        require_once(dirname(__FILE__) . '/vendor/readme-parser.php');\r
                }\r
                $parser = new PucReadmeParser();\r
index 38760f4..b9a9852 100644 (file)
@@ -1,4 +1,5 @@
 <?php\r
+namespace GLMServerStats;\r
 /**\r
  * Plugin Update Checker Library 3.1\r
  * http://w-shadow.com/\r
@@ -7,7 +8,7 @@
  * Released under the MIT license. See license.txt for details.\r
  */\r
 \r
-if ( !class_exists('PluginUpdateChecker_3_1', false) ):\r
+if ( !class_exists('GLMServerStats\PluginUpdateChecker_3_1', false) ):\r
 \r
 /**\r
  * A custom plugin update checker.\r
@@ -376,7 +377,7 @@ class PluginUpdateChecker_3_1 {
 \r
         $state = $this->getUpdateState();\r
         if ( empty($state) ){\r
-            $state = new stdClass;\r
+            $state = new \stdClass;\r
             $state->lastCheck = 0;\r
             $state->checkedVersion = '';\r
             $state->update = null;\r
@@ -497,7 +498,7 @@ class PluginUpdateChecker_3_1 {
      */\r
     private function addUpdateToList($updates, $updateToAdd) {\r
         if ( !is_object($updates) ) {\r
-            $updates = new stdClass();\r
+            $updates = new \stdClass();\r
             $updates->response = array();\r
         }\r
 \r
@@ -541,7 +542,7 @@ class PluginUpdateChecker_3_1 {
 \r
         //Being defensive.\r
         if ( !is_object($updates) ) {\r
-            $updates = new stdClass();\r
+            $updates = new \stdClass();\r
         }\r
         if ( !isset($updates->translations) ) {\r
             $updates->translations = array();\r
@@ -934,7 +935,7 @@ class PluginUpdateChecker_3_1 {
      */\r
     public function initDebugBarPanel() {\r
         $debugBarPlugin = dirname(__FILE__) . '/debug-bar-plugin.php';\r
-        if ( class_exists('Debug_Bar', false) && file_exists($debugBarPlugin) ) {\r
+        if ( class_exists('GLMServerStats\Debug_Bar', false) && file_exists($debugBarPlugin) ) {\r
             /** @noinspection PhpIncludeInspection */\r
             require_once $debugBarPlugin;\r
             $this->debugBarPlugin = new PucDebugBarPlugin_3_1($this);\r
@@ -956,7 +957,7 @@ class PluginUpdateChecker_3_1 {
 \r
 endif;\r
 \r
-if ( !class_exists('PluginInfo_3_1', false) ):\r
+if ( !class_exists('GLMServerStats\PluginInfo_3_1', false) ):\r
 \r
 /**\r
  * A container class for holding and transforming various plugin metadata.\r
@@ -1057,7 +1058,7 @@ class PluginInfo_3_1 {
      * @return object\r
      */\r
     public function toWpFormat(){\r
-        $info = new stdClass;\r
+        $info = new \stdClass;\r
 \r
         //The custom update API is built so that many fields have the same name and format\r
         //as those returned by the native WordPress.org API. These can be assigned directly.\r
@@ -1098,7 +1099,7 @@ class PluginInfo_3_1 {
 \r
 endif;\r
 \r
-if ( !class_exists('PluginUpdate_3_1', false) ):\r
+if ( !class_exists('GLMServerStats\PluginUpdate_3_1', false) ):\r
 \r
 /**\r
  * A simple container class for holding information about an available update.\r
@@ -1184,7 +1185,7 @@ class PluginUpdate_3_1 {
      * @return StdClass\r
      */\r
     public function toStdClass() {\r
-        $object = new stdClass();\r
+        $object = new \stdClass();\r
         $fields = self::$fields;\r
         if ( !empty($this->slug) ) {\r
             $fields = apply_filters('puc_retain_fields-' . $this->slug, $fields);\r
@@ -1204,7 +1205,7 @@ class PluginUpdate_3_1 {
      * @return object\r
      */\r
     public function toWpFormat(){\r
-        $update = new stdClass;\r
+        $update = new \stdClass;\r
 \r
         $update->id = $this->id;\r
         $update->slug = $this->slug;\r
@@ -1224,7 +1225,7 @@ class PluginUpdate_3_1 {
 \r
 endif;\r
 \r
-if ( !class_exists('PucScheduler_3_1', false) ):\r
+if ( !class_exists('GLMServerStats\PucScheduler_3_1', false) ):\r
 \r
 /**\r
  * The scheduler decides when and how often to check for updates.\r
@@ -1403,7 +1404,7 @@ class PucScheduler_3_1 {
 endif;\r
 \r
 \r
-if ( !class_exists('PucUpgraderStatus_3_1', false) ):\r
+if ( !class_exists('GLMServerStats\PucUpgraderStatus_3_1', false) ):\r
 \r
 /**\r
  * A utility class that helps figure out which plugin WordPress is upgrading.\r
@@ -1548,7 +1549,7 @@ class PucUpgraderStatus_3_1 {
 endif;\r
 \r
 \r
-if ( !class_exists('PucFactory', false) ):\r
+if ( !class_exists('GLMServerStats\GLMServerStats\PucFactory', false) ):\r
 \r
 /**\r
  * A factory that builds instances of other classes from this library.\r
index a861b18..9c974d6 100644 (file)
@@ -237,7 +237,7 @@ Class PucReadmeParser {
                $text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
 
                if ( $markdown ) { // Parse markdown.
-                       if ( !class_exists('Parsedown', false) ) {
+                       if ( !class_exists('GLMServerStats\Parsedown', false) ) {
                                require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');
                        }
                        $instance = Parsedown::instance();
@@ -264,7 +264,7 @@ Class PucReadmeParser {
                );
 
                $text = balanceTags($text);
-               
+
                $text = wp_kses( $text, $allowed );
                $text = trim($text);
                return $text;
index 2d46014..534443a 100755 (executable)
@@ -1,5 +1,5 @@
 <?php
-
+namespace GLMServerStats;
 /**
  * Gaslight Media - GLM Bandwidth
  * Smarty Templates Support Class
@@ -54,8 +54,10 @@ class glmBandwidthStatsSmartyTemplateSupport {
                /*
                 * Load and instatiate Smarty Templates
                 */
-               require_once GLM_SERVERSTATS_PLUGIN_PATH.'/lib/smarty-3.1.33/libs/SmartyBC.class.php';
-               $this->template = new SmartyBC ();
+           if ( !class_exists( '\SmartyBC' ) ) {
+            require_once GLM_SERVERSTATS_PLUGIN_PATH.'/lib/smarty-3.1.33/libs/SmartyBC.class.php';
+           }
+               $this->template = new \SmartyBC ();
 
                /*
                 * Configure Smarty Templates for this site
index a60c153..b2626e6 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media - GLM Bandwidth
  *
index 2a9e0de..f279052 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media = GLM Bandwidth
  * Send Usage Report(s)
index ae84436..541ba9a 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media = GLM Bandwidth
  * Server Bandwidth Stats by AJAX
@@ -112,10 +113,12 @@ class ajaxServerBandwidthGraphs  extends glmServerStatsBandwidthSupport
         }
 
         // Load PHPGraphLib
-        require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/phpgraphlib-master/phpgraphlib.php';
+        if ( !class_exists( '\PHPGraphLib' ) ) {
+            require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/phpgraphlib-master/phpgraphlib.php';
+        }
 
         // Create graph object and set parameters
-        $graph = new PHPGraphLib(1200,300);
+        $graph = new \PHPGraphLib(1200,300);
         $graph->setXValues(true);
         $graph->setYValues(true);
         $graph->setMinMaxY(1); // Set minimum top value to Y axis
index f10b66b..ee80f5c 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 // Get Configuration for Cookie info popup
 
 $bwdb = mysqli_init();
index c027a2a..c532d42 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media Server Bandwidth - Stand Alone
  * Server Bandwidth Support Abstract
index f7b784f..3dee578 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media - GLM Bandwidth
  * Server Bandwidth Stats Target Check Class
index 696c286..6a70361 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media Members Database
  * GLM Members Misc Admin Hooks and Filters
index 72b2e38..04b60cc 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media - GLM Bandwidth
  *
@@ -18,18 +19,19 @@ if (current_user_can('editor') || current_user_can('administrator')) {
     global $websiteSettings;
 
     // If show usage is enabled from main site or if administrator, show usage menu
-    if( $websiteSettings['show_usage'] || current_user_can('administrator') )
-    add_menu_page(
-        "GLM Data Usage",
-        'GLM Data Usage',
-        'edit_pages',
-        'glm-server-stats-main-menu',
-        function() {
-            serverStatsController('adminServerStats');
-        },
-        GLM_SERVERSTATS_PLUGIN_ASSETS_URL.'/flame.png',
-        '3.100'
-    );
+    if( $websiteSettings['show_usage'] || current_user_can('administrator') ) {
+        add_menu_page(
+            "GLM Data Usage",
+            'GLM Data Usage',
+            'edit_pages',
+            'glm-server-stats-main-menu',
+            function() {
+                serverStatsController('adminServerStats');
+            },
+            GLM_SERVERSTATS_PLUGIN_ASSETS_URL.'/flame.png',
+            '3.100'
+        );
+    }
 
     add_menu_page(
         'GLM Notifications',
index b996e3e..4096cf5 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media Members Database
  * GLM Members Misc Common Hooks and Filters
@@ -46,18 +47,17 @@ add_filter('glm-serverstats-is-provider', function() {
 /*
  * Shortcode to output contact information for the bottom of the cookie and policy page created by this plugin.
  */
-function policy_contact_shortcode( $atts ){
+add_shortcode( 'policy_contact', function($atts) {
     global $websiteSettings;
     return
-         (!empty($websiteSettings['contact_name'])?$websiteSettings['contact_name']."<br>":'')
-        .(!empty($websiteSettings['contact_org'])?$websiteSettings['contact_org']."<br>":'')
-        .(!empty($websiteSettings['contact_address'])?$websiteSettings['contact_address']."<br>":'')
-        .(!empty($websiteSettings['contact_address2'])?$websiteSettings['contact_address2']."<br>":'')
-        .(!empty($websiteSettings['contact_city'])?$websiteSettings['contact_city']:'')
-        .(!empty($websiteSettings['contact_state'])?", ".$websiteSettings['contact_state']:'')
-        .(!empty($websiteSettings['contact_zip'])?" ".$websiteSettings['contact_zip']:'')
-        .(!empty($websiteSettings['contact_city'])||!empty($websiteSettings['contact_state'])||!empty($websiteSettings['contact_zip'])?"<br>":'')
-        .(!empty($websiteSettings['contact_phone'])?"<br>Phone: ".$websiteSettings['contact_phone']:'')
-        .(!empty($websiteSettings['contact_email'])?"<br>E-Mail: ".$websiteSettings['contact_email']:'');
-}
-add_shortcode( 'policy_contact', 'policy_contact_shortcode' );
+    (!empty($websiteSettings['contact_name'])?$websiteSettings['contact_name']."<br>":'')
+    .(!empty($websiteSettings['contact_org'])?$websiteSettings['contact_org']."<br>":'')
+    .(!empty($websiteSettings['contact_address'])?$websiteSettings['contact_address']."<br>":'')
+    .(!empty($websiteSettings['contact_address2'])?$websiteSettings['contact_address2']."<br>":'')
+    .(!empty($websiteSettings['contact_city'])?$websiteSettings['contact_city']:'')
+    .(!empty($websiteSettings['contact_state'])?", ".$websiteSettings['contact_state']:'')
+    .(!empty($websiteSettings['contact_zip'])?" ".$websiteSettings['contact_zip']:'')
+    .(!empty($websiteSettings['contact_city'])||!empty($websiteSettings['contact_state'])||!empty($websiteSettings['contact_zip'])?"<br>":'')
+    .(!empty($websiteSettings['contact_phone'])?"<br>Phone: ".$websiteSettings['contact_phone']:'')
+    .(!empty($websiteSettings['contact_email'])?"<br>E-Mail: ".$websiteSettings['contact_email']:'');
+});
index 4fc99a6..5d286e8 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace GLMServerStats;
 /**
  * Gaslight Media - GLM Bandwidth
  * Standard Template Parameters
index 92fda27..64c6ac1 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+namespace GLMServerStats;
 die('uninstall not configured - See plugin uninstall.php script!');
 
 /**