Controllers
4 years ago
Helpers
4 years ago
Models
4 years ago
Widgets
4 years ago
RtTpg.php
4 years ago
RtTpg.php
223 lines
| 1 | <?php |
| 2 | |
| 3 | use RT\ThePostGrid\Controllers\Admin\AdminAjaxController; |
| 4 | use RT\ThePostGrid\Controllers\Admin\MetaController; |
| 5 | use RT\ThePostGrid\Controllers\Admin\NoticeController; |
| 6 | use RT\ThePostGrid\Controllers\Admin\PostTypeController; |
| 7 | use RT\ThePostGrid\Controllers\Admin\SettingsController; |
| 8 | use RT\ThePostGrid\Controllers\AjaxController; |
| 9 | use RT\ThePostGrid\Controllers\ElementorController; |
| 10 | use RT\ThePostGrid\Controllers\GutenBergController; |
| 11 | use RT\ThePostGrid\Controllers\ScriptController; |
| 12 | use RT\ThePostGrid\Controllers\ShortcodeController; |
| 13 | use RT\ThePostGrid\Controllers\Hooks\FilterHooks; |
| 14 | use RT\ThePostGrid\Controllers\Hooks\ActionHooks; |
| 15 | use RT\ThePostGrid\Controllers\WidgetController; |
| 16 | use RT\ThePostGrid\Helpers\Install; |
| 17 | use RT\ThePostGrid\Controllers\Admin\UpgradeController; |
| 18 | |
| 19 | require_once __DIR__ . './../vendor/autoload.php'; |
| 20 | |
| 21 | if ( ! class_exists( RtTpg::class ) ) { |
| 22 | final class RtTpg { |
| 23 | |
| 24 | public $test; |
| 25 | public $post_type = "rttpg"; |
| 26 | public $options = [ |
| 27 | 'settings' => 'rt_the_post_grid_settings', |
| 28 | 'version' => RT_THE_POST_GRID_VERSION, |
| 29 | 'installed_version' => 'rt_the_post_grid_current_version', |
| 30 | 'slug' => RT_THE_POST_GRID_PLUGIN_SLUG, |
| 31 | ]; |
| 32 | public $defaultSettings = [ |
| 33 | 'popup_fields' => [ |
| 34 | 'title', |
| 35 | 'feature_img', |
| 36 | 'content', |
| 37 | 'post_date', |
| 38 | 'author', |
| 39 | 'categories', |
| 40 | 'tags', |
| 41 | 'social_share', |
| 42 | ], |
| 43 | 'social_share_items' => [ |
| 44 | 'facebook', |
| 45 | 'twitter', |
| 46 | 'linkedin', |
| 47 | ], |
| 48 | ]; |
| 49 | |
| 50 | protected static $_instance; |
| 51 | |
| 52 | /** |
| 53 | * Store the singleton object. |
| 54 | */ |
| 55 | private static $singleton = false; |
| 56 | |
| 57 | /** |
| 58 | * Create an inaccessible constructor. |
| 59 | */ |
| 60 | private function __construct() { |
| 61 | $this->test = 'test value'; |
| 62 | $this->__init(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Fetch an instance of the class. |
| 67 | */ |
| 68 | final public static function getInstance() { |
| 69 | if ( self::$singleton === false ) { |
| 70 | self::$singleton = new self(); |
| 71 | } |
| 72 | |
| 73 | return self::$singleton; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | protected function __init() { |
| 78 | if ( $this->hasPro() && UpgradeController::check_plugin_version() == false ) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | $settings = get_option( $this->options['settings'] ); |
| 83 | |
| 84 | new PostTypeController(); |
| 85 | new AjaxController(); |
| 86 | new ScriptController(); |
| 87 | new WidgetController(); |
| 88 | |
| 89 | if ( is_admin() ) { |
| 90 | new AdminAjaxController(); |
| 91 | new NoticeController(); |
| 92 | new MetaController(); |
| 93 | } |
| 94 | |
| 95 | if ( ! isset( $settings['tpg_block_type'] ) || in_array( $settings['tpg_block_type'], [ 'default', |
| 96 | 'shortcode' |
| 97 | ] ) ) { |
| 98 | new ShortcodeController(); |
| 99 | new GutenBergController(); |
| 100 | } |
| 101 | |
| 102 | FilterHooks::init(); |
| 103 | ActionHooks::init(); |
| 104 | |
| 105 | ( new SettingsController() )->init(); |
| 106 | |
| 107 | if ( ! isset( $settings['tpg_block_type'] ) || in_array( $settings['tpg_block_type'], [ 'default', |
| 108 | 'elementor' |
| 109 | ] ) ) { |
| 110 | new ElementorController(); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | $this->load_hooks(); |
| 115 | } |
| 116 | |
| 117 | private function load_hooks() { |
| 118 | register_activation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'activate' ] ); |
| 119 | register_deactivation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'deactivate' ] ); |
| 120 | |
| 121 | add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], - 1 ); |
| 122 | add_action( 'init', [ &$this, 'init_hooks' ], 0 ); |
| 123 | //add_action( 'init', [ ShortcodeController::class, 'init' ] ); // Init ShortCode. |
| 124 | add_filter( 'wp_calculate_image_srcset', '__return_false' ); |
| 125 | } |
| 126 | |
| 127 | public function init_hooks() { |
| 128 | do_action( 'rttpg_before_init', $this ); |
| 129 | |
| 130 | $this->load_language(); |
| 131 | } |
| 132 | |
| 133 | public function load_language() { |
| 134 | do_action( 'rttpg_set_local', null ); |
| 135 | $locale = determine_locale(); |
| 136 | $locale = apply_filters( 'plugin_locale', $locale, 'the-post-grid' ); |
| 137 | unload_textdomain( 'the-post-grid' ); |
| 138 | load_textdomain( 'the-post-grid', WP_LANG_DIR . '/the-post-grid/the-post-grid-' . $locale . '.mo' ); |
| 139 | load_plugin_textdomain( 'the-post-grid', false, plugin_basename( dirname( RT_THE_POST_GRID_PLUGIN_FILE ) ) . '/languages' ); |
| 140 | } |
| 141 | |
| 142 | public function on_plugins_loaded() { |
| 143 | do_action( 'rttpg_loaded', $this ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Get the plugin path. |
| 148 | * |
| 149 | * @return string |
| 150 | */ |
| 151 | public function plugin_path() { |
| 152 | return untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) ); |
| 153 | } |
| 154 | |
| 155 | public function plugin_template_path() { |
| 156 | $plugin_template = $this->plugin_path() . '/templates/'; |
| 157 | |
| 158 | return apply_filters( 'tlp_tpg_template_path', $plugin_template ); |
| 159 | } |
| 160 | |
| 161 | public function default_template_path() { |
| 162 | return apply_filters( 'rttpg_default_template_path', untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) ) ); |
| 163 | } |
| 164 | |
| 165 | public static function nonceText() { |
| 166 | return "rttpg_nonce_secret"; |
| 167 | } |
| 168 | |
| 169 | public static function nonceId() { |
| 170 | return "rttpg_nonce"; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @param $file |
| 175 | * |
| 176 | * @return string |
| 177 | */ |
| 178 | public function get_assets_uri( $file ) { |
| 179 | $file = ltrim( $file, '/' ); |
| 180 | |
| 181 | return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @param $file |
| 186 | * |
| 187 | * @return string |
| 188 | */ |
| 189 | public function tpg_can_be_rtl( $file ) { |
| 190 | $file = ltrim( str_replace( '.css', '', $file ), '/' ); |
| 191 | |
| 192 | if ( is_rtl() ) { |
| 193 | $file .= '.rtl'; |
| 194 | } |
| 195 | |
| 196 | return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file . '.min.css'; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Get the template path. |
| 201 | * |
| 202 | * @return string |
| 203 | */ |
| 204 | public function get_template_path() { |
| 205 | return apply_filters( 'rttpg_template_path', 'the-post-grid/' ); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | public function hasPro() { |
| 210 | return class_exists( 'RtTpgPro' ) || class_exists( 'rtTPGP' ); |
| 211 | } |
| 212 | |
| 213 | } |
| 214 | |
| 215 | function rtTPG() { |
| 216 | return rtTPG::getInstance(); |
| 217 | } |
| 218 | |
| 219 | rtTPG(); |
| 220 | } |
| 221 | |
| 222 | |
| 223 |