| 1 |
<?php |
| 2 |
// +----------------------------------------------------------------------+ |
| 3 |
// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 4 |
// +----------------------------------------------------------------------+ |
| 5 |
// | This program is free software; you can redistribute it and/or modify | |
| 6 |
// | it under the terms of the GNU General Public License, version 2, as | |
| 7 |
// | published by the Free Software Foundation. | |
| 8 |
// | | |
| 9 |
// | This program is distributed in the hope that it will be useful, | |
| 10 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 |
// | GNU General Public License for more details. | |
| 13 |
// | | |
| 14 |
// | You should have received a copy of the GNU General Public License | |
| 15 |
// | along with this program; if not, write to the Free Software | |
| 16 |
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 17 |
// | MA 02110-1301 USA | |
| 18 |
// +----------------------------------------------------------------------+ |
| 19 |
// | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 20 |
// +----------------------------------------------------------------------+ |
| 21 |
/** |
| 22 |
* The core plugin class. |
| 23 |
* |
| 24 |
* @category Visualizer |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
class Visualizer_Plugin { |
| 29 |
|
| 30 |
const NAME = 'visualizer'; |
| 31 |
const VERSION = '2.1.9'; |
| 32 |
|
| 33 |
// custom post types |
| 34 |
const CPT_VISUALIZER = 'visualizer'; |
| 35 |
|
| 36 |
// custom meta fields |
| 37 |
const CF_CHART_TYPE = 'visualizer-chart-type'; |
| 38 |
const CF_SOURCE = 'visualizer-source'; |
| 39 |
const CF_SERIES = 'visualizer-series'; |
| 40 |
const CF_DEFAULT_DATA = 'visualizer-default-data'; |
| 41 |
const CF_SETTINGS = 'visualizer-settings'; |
| 42 |
|
| 43 |
// custom actions |
| 44 |
const ACTION_GET_CHARTS = 'visualizer-get-charts'; |
| 45 |
const ACTION_CREATE_CHART = 'visualizer-create-chart'; |
| 46 |
const ACTION_EDIT_CHART = 'visualizer-edit-chart'; |
| 47 |
const ACTION_CLONE_CHART = 'visualizer-clone-chart'; |
| 48 |
const ACTION_DELETE_CHART = 'visualizer-delete-chart'; |
| 49 |
const ACTION_UPLOAD_DATA = 'visualizer-upload-data'; |
| 50 |
// Added by Ash/Upwork |
| 51 |
const ACTION_EXPORT_DATA = 'visualizer-export-data'; |
| 52 |
|
| 53 |
// custom filters |
| 54 |
const FILTER_CHART_WRAPPER_CLASS = 'visualizer-chart-wrapper-class'; |
| 55 |
const FILTER_GET_CHART_SERIES = 'visualizer-get-chart-series'; |
| 56 |
const FILTER_GET_CHART_DATA = 'visualizer-get-chart-data'; |
| 57 |
const FILTER_GET_CHART_SETTINGS = 'visualizer-get-chart-settings'; |
| 58 |
|
| 59 |
const CF_CHART_URL = 'visualizer-chart-url'; |
| 60 |
const CF_CHART_SCHEDULE = 'visualizer-chart-schedule'; |
| 61 |
// Added by Ash/Upwork |
| 62 |
const PRO_TEASER_URL = 'http://themeisle.com/plugins/visualizer-charts-and-graphs-pro-addon/'; |
| 63 |
const PRO_TEASER_TITLE = 'Check PRO version '; |
| 64 |
// Added by Ash/Upwork |
| 65 |
/** |
| 66 |
* Singletone instance of the plugin. |
| 67 |
* |
| 68 |
* @since 1.0.0 |
| 69 |
* |
| 70 |
* @access private |
| 71 |
* @var Visualizer_Plugin |
| 72 |
*/ |
| 73 |
private static $_instance = null; |
| 74 |
|
| 75 |
/** |
| 76 |
* The array of registered modules. |
| 77 |
* |
| 78 |
* @since 1.0.0 |
| 79 |
* |
| 80 |
* @access private |
| 81 |
* @var array |
| 82 |
*/ |
| 83 |
private $_modules = array(); |
| 84 |
|
| 85 |
/** |
| 86 |
* Private constructor. |
| 87 |
* |
| 88 |
* @since 1.0.0 |
| 89 |
* |
| 90 |
* @access private |
| 91 |
*/ |
| 92 |
private function __construct() { |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns singletone instance of the plugin. |
| 97 |
* |
| 98 |
* @since 1.0.0 |
| 99 |
* |
| 100 |
* @static |
| 101 |
* @access public |
| 102 |
* @return Visualizer_Plugin |
| 103 |
*/ |
| 104 |
public static function instance() { |
| 105 |
if ( is_null( self::$_instance ) ) { |
| 106 |
self::$_instance = new Visualizer_Plugin(); |
| 107 |
} |
| 108 |
|
| 109 |
return self::$_instance; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Returns chart types. |
| 114 |
* |
| 115 |
* @since 1.0.0 |
| 116 |
* |
| 117 |
* @static |
| 118 |
* @access public |
| 119 |
* @return array |
| 120 |
*/ |
| 121 |
public static function getChartTypes() { |
| 122 |
$array = array_keys( Visualizer_Module_Admin::_getChartTypesLocalized() ); |
| 123 |
|
| 124 |
return $array; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Returns a module if it was registered before. Otherwise NULL. |
| 129 |
* |
| 130 |
* @since 1.0.0 |
| 131 |
* |
| 132 |
* @access public |
| 133 |
* |
| 134 |
* @param string $name The name of the module to return. |
| 135 |
* |
| 136 |
* @return Visualizer_Module|null Returns a module if it was registered or NULL. |
| 137 |
*/ |
| 138 |
public function getModule( $name ) { |
| 139 |
return isset( $this->_modules[ $name ] ) ? $this->_modules[ $name ] : null; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Determines whether the module has been registered or not. |
| 144 |
* |
| 145 |
* @since 1.0.0 |
| 146 |
* |
| 147 |
* @access public |
| 148 |
* |
| 149 |
* @param string $name The name of a module to check. |
| 150 |
* |
| 151 |
* @return boolean TRUE if the module has been registered. Otherwise FALSE. |
| 152 |
*/ |
| 153 |
public function hasModule( $name ) { |
| 154 |
return isset( $this->_modules[ $name ] ); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Register new module in the plugin. |
| 159 |
* |
| 160 |
* @since 1.0.0 |
| 161 |
* |
| 162 |
* @access public |
| 163 |
* |
| 164 |
* @param string $class The name of the module to use in the plugin. |
| 165 |
*/ |
| 166 |
public function setModule( $class ) { |
| 167 |
$this->_modules[ $class ] = new $class( $this ); |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Private clone method. |
| 172 |
* |
| 173 |
* @since 1.0.0 |
| 174 |
* |
| 175 |
* @access private |
| 176 |
*/ |
| 177 |
private function __clone() { |
| 178 |
} |
| 179 |
|
| 180 |
} |
| 181 |
|