| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace cx_newsletter;
- use \add_action;
- use \add_filter;
- use \load_plugin_textdomain;
- use \wp_next_scheduled;
- use \wp_schedule_event;
- use \add_menu_page;
- use \wpdb;
- class plugin {
- public function __construct(string $plugin) {
- add_action('admin_menu', [$this, 'admin']);
- add_action('init', [$this, 'init']);
- add_action('rest_api_init', [$this, 'register_rest']);
- add_action('cx_newsletter_email_sender', [$this, 'email_sender']);
- add_filter('cron_schedules', [$this, 'add_schedules']);
-
- global $wpdb;
- $this->database = $wpdb;
- $this->plugin = $plugin;
- $directory = new \cx_appengine\directory(templates_dir, 'html');
- $dictionary = new wordpress_dictionary;
- $this->templates = new \cx_appengine\templates($directory, $dictionary);
- $this->settings = new plugin_settings();
- $this->tables = new table_names($this->get_database());
- $this->versions = new database_versions_manager();
- $this->init_cron();
- }
- public function init() {
- $this->export = new customers_export_page(
- $this->database,
- $this->tables,
- $this->settings
- );
- $this->export->prepare();
- $this->translations();
- }
-
- private function translations() : void {
- load_plugin_textdomain(
- 'cx_newsletter',
- false,
- $this->plugin.'/translates');
- }
- public function add_schedules(array $intervals) : array {
- $intervals['cx_newsletter_send'] = [];
- $intervals['cx_newsletter_send']['interval'] = 60;
- $intervals['cx_newsletter_send']['display'] = 'cx-newsletter';
- return $intervals;
- }
- public function register_rest() : void {
- $this->messages_get = new messages_get_endpoint(
- $this->database,
- $this->settings,
- $this->tables
- );
- $this->messages_send = new messages_send_endpoint(
- $this->database,
- $this->settings,
- $this->tables
- );
- $this->settings_check = new settings_check_endpoint(
- $this->database,
- $this->settings,
- $this->tables
- );
- $registerer = new rest_register('cx-newsletter/v1');
- $registerer
- ->register($this->messages_get)
- ->register($this->messages_send)
- ->register($this->settings_check);
- }
- private function init_cron() : void {
- if (wp_next_scheduled('cx_newsletter_email_sender') === false) {
- wp_schedule_event(
- time(),
- 'cx_newsletter_send',
- 'cx_newsletter_email_sender'
- );
- }
- }
-
- public function email_sender() {
- $sender = new cron_emails_sender(
- $this->database,
- $this->tables,
- $this->settings
- );
- $sender
- ->prepare()
- ->process();
- }
- public function admin() {
- $this->update();
- $this->connect_menu();
- $config_panel = new config_panel_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
- $dashboard = new dashboard_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
- $manage_messages = new manage_messages_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
-
- $manage_customers = new manage_customers_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
- $show_campaigns = new show_campaigns_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
-
- $manage_groups = new manage_groups_view(
- $this->get_database(),
- $this->get_settings(),
- $this->get_templates(),
- $this->get_tables()
- );
- $config_panel->connect();
- $dashboard->connect();
- $manage_messages->connect();
- $manage_customers->connect();
- $show_campaigns->connect();
- $manage_groups->connect();
- }
- private function connect_menu() : void {
- add_menu_page(
- 'cx-newsletter',
- 'cx-newsletter',
- 'customize',
- 'cx_newsletter',
- '',
- 'dashicons-art'
- );
- }
- public function update() {
- $this
- ->get_plugin_updater()
- ->update();
- }
- private function get_plugin_updater() : plugin_updater {
- return new plugin_updater(
- $this->get_settings(),
- $this->get_versions(),
- $this->get_tables(),
- $this->get_database()
- );
- }
- public function install() {
- $this
- ->get_plugin_updater()
- ->install();
- }
- public function remove() {
- $this
- ->get_plugin_updater()
- ->remove();
- }
- protected function get_database() : wpdb {
- return $this->database;
- }
- protected function get_templates() : \cx_appengine\templates {
- return $this->templates;
- }
- protected function get_settings() : settings {
- return $this->settings;
- }
- protected function get_tables() : table_names {
- return $this->tables;
- }
- protected function get_versions() : database_versions_manager {
- return $this->versions;
- }
-
- private string $plugin;
- private \cx_appengine\templates $templates;
- private wpdb $database;
- private table_names $tables;
- private settings $settings;
- private messages_get_endpoint $messages_get;
- private messages_send_endpoint $messages_send;
- private settings_check_endpoint $settings_check;
- private database_versions_manager $versions;
- }
|