Controllers
4 years ago
Helpers
4 years ago
Models
4 years ago
Widgets
4 years ago
RtTpg.php
4 years ago
RtTpg.php
220 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 $post_type = "rttpg"; |
| 25 | public $options = [ |
| 26 | 'settings' => 'rt_the_post_grid_settings', |
| 27 | 'version' => RT_THE_POST_GRID_VERSION, |
| 28 | 'installed_version' => 'rt_the_post_grid_current_version', |
| 29 | 'slug' => RT_THE_POST_GRID_PLUGIN_SLUG, |
| 30 | ]; |
| 31 | public $defaultSettings = [ |
| 32 | 'tpg_block_type' => 'default', |
| 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->__init(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Fetch an instance of the class. |
| 66 | */ |
| 67 | final public static function getInstance() { |
| 68 | if ( self::$singleton === false ) { |
| 69 | self::$singleton = new self(); |
| 70 | } |
| 71 | |
| 72 | return self::$singleton; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | protected function __init() { |
| 77 | |
| 78 | $settings = get_option( $this->options['settings'] ); |
| 79 | |
| 80 | new UpgradeController(); |
| 81 | new PostTypeController(); |
| 82 | new AjaxController(); |
| 83 | new ScriptController(); |
| 84 | new WidgetController(); |
| 85 | |
| 86 | if ( is_admin() ) { |
| 87 | new AdminAjaxController(); |
| 88 | new NoticeController(); |
| 89 | new MetaController(); |
| 90 | } |
| 91 | |
| 92 | if ( ! isset( $settings['tpg_block_type'] ) || in_array( $settings['tpg_block_type'], [ 'default', |
| 93 | 'shortcode' |
| 94 | ] ) ) { |
| 95 | new ShortcodeController(); |
| 96 | new GutenBergController(); |
| 97 | } |
| 98 | |
| 99 | FilterHooks::init(); |
| 100 | ActionHooks::init(); |
| 101 | |
| 102 | ( new SettingsController() )->init(); |
| 103 | |
| 104 | if ( ! isset( $settings['tpg_block_type'] ) || in_array( $settings['tpg_block_type'], [ 'default', |
| 105 | 'elementor' |
| 106 | ] ) ) { |
| 107 | new ElementorController(); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | $this->load_hooks(); |
| 112 | } |
| 113 | |
| 114 | private function load_hooks() { |
| 115 | register_activation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'activate' ] ); |
| 116 | register_deactivation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'deactivate' ] ); |
| 117 | |
| 118 | add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], - 1 ); |
| 119 | add_action( 'init', [ &$this, 'init_hooks' ], 0 ); |
| 120 | //add_action( 'init', [ ShortcodeController::class, 'init' ] ); // Init ShortCode. |
| 121 | add_filter( 'wp_calculate_image_srcset', '__return_false' ); |
| 122 | } |
| 123 | |
| 124 | public function init_hooks() { |
| 125 | do_action( 'rttpg_before_init', $this ); |
| 126 | |
| 127 | $this->load_language(); |
| 128 | } |
| 129 | |
| 130 | public function load_language() { |
| 131 | do_action( 'rttpg_set_local', null ); |
| 132 | $locale = determine_locale(); |
| 133 | $locale = apply_filters( 'plugin_locale', $locale, 'the-post-grid' ); |
| 134 | unload_textdomain( 'the-post-grid' ); |
| 135 | load_textdomain( 'the-post-grid', WP_LANG_DIR . '/the-post-grid/the-post-grid-' . $locale . '.mo' ); |
| 136 | load_plugin_textdomain( 'the-post-grid', false, plugin_basename( dirname( RT_THE_POST_GRID_PLUGIN_FILE ) ) . '/languages' ); |
| 137 | } |
| 138 | |
| 139 | public function on_plugins_loaded() { |
| 140 | do_action( 'rttpg_loaded', $this ); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Get the plugin path. |
| 145 | * |
| 146 | * @return string |
| 147 | */ |
| 148 | public function plugin_path() { |
| 149 | return untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) ); |
| 150 | } |
| 151 | |
| 152 | public function plugin_template_path() { |
| 153 | $plugin_template = $this->plugin_path() . '/templates/'; |
| 154 | |
| 155 | return apply_filters( 'tlp_tpg_template_path', $plugin_template ); |
| 156 | } |
| 157 | |
| 158 | public function default_template_path() { |
| 159 | return apply_filters( 'rttpg_default_template_path', untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) ) ); |
| 160 | } |
| 161 | |
| 162 | public static function nonceText() { |
| 163 | return "rttpg_nonce_secret"; |
| 164 | } |
| 165 | |
| 166 | public static function nonceId() { |
| 167 | return "rttpg_nonce"; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param $file |
| 172 | * |
| 173 | * @return string |
| 174 | */ |
| 175 | public function get_assets_uri( $file ) { |
| 176 | $file = ltrim( $file, '/' ); |
| 177 | |
| 178 | return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * @param $file |
| 183 | * |
| 184 | * @return string |
| 185 | */ |
| 186 | public function tpg_can_be_rtl( $file ) { |
| 187 | $file = ltrim( str_replace( '.css', '', $file ), '/' ); |
| 188 | |
| 189 | if ( is_rtl() ) { |
| 190 | $file .= '.rtl'; |
| 191 | } |
| 192 | |
| 193 | return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file . '.min.css'; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Get the template path. |
| 198 | * |
| 199 | * @return string |
| 200 | */ |
| 201 | public function get_template_path() { |
| 202 | return apply_filters( 'rttpg_template_path', 'the-post-grid/' ); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | public function hasPro() { |
| 207 | return class_exists( 'RtTpgPro' ) || class_exists( 'rtTPGP' ); |
| 208 | } |
| 209 | |
| 210 | } |
| 211 | |
| 212 | function rtTPG() { |
| 213 | return rtTPG::getInstance(); |
| 214 | } |
| 215 | |
| 216 | rtTPG(); |
| 217 | } |
| 218 | |
| 219 | |
| 220 |