settings.php 7.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php
if(!class_exists('Mailman_Integration_Settings'))
{
	class Mailman_Integration_Settings
	{
		/**
		 * Construct the plugin object
		 */
		public function __construct()
		{
			// register actions
            add_action('admin_init', array(&$this, 'admin_init'));
        	add_action('admin_menu', array(&$this, 'add_menu'));
		} // END public function __construct
		
        /**
         * hook into WP's admin_init action hook
         */
        public function admin_init()
        {
        	$this->setting_fields();
        } // END public function admin_init


        public function setting_fields(){
            // Register all settings
            register_setting('mailman_integration-group', 'mmi_admin_list_url');
            register_setting('mailman_integration-group', 'mmi_mailing_lists');
29
            register_setting('mailman_integration-group', 'mmi_mailing_lists_nonpublic');
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

            // Settings sections
            add_settings_section(
                'mmi-list-settings-section', 
                'Mailing list settings', 
                array(&$this, 'settings_section_mmi_list_settings'), 
                'mailman_integration'
            );
            
            // Settings fields - Mailing list settings section
            add_settings_field(
                'mailman_integration-mmi_admin_list_url', 
                'Admin list URL', 
                array(&$this, 'settings_field_input_text'), 
                'mailman_integration', 
                'mmi-list-settings-section',
                array(
                    'field' => 'mmi_admin_list_url',
48
                    'desc' => '<br><button id="refresh-lists-button" class="button button-primary" type="button">Refresh mailing lists</button>',
49 50 51
                    'placeholder' => 'http://example.com/mailman/admin'
                )
            );
52

53 54
            add_settings_field(
                'mailman_integration-mmi_mailing_lists', 
55
                'Public mailing lists', 
56 57 58 59 60
                array(&$this, 'settings_field_textarea'), 
                'mailman_integration', 
                'mmi-list-settings-section',
                array(
                    'field' => 'mmi_mailing_lists',
61 62
                    'desc' => '<div id="mailing-lists-list" style="font-style:normal;"><img src="images/wpspin_light.gif" alt="Loading..."></div>',
                    'style' => 'display:none'
63 64
                )
            );
65 66 67 68 69 70 71 72 73 74 75 76 77

            add_settings_field(
                'mailman_integration-mmi_mailing_lists_nonpublic', 
                'Add non-public mailing lists manually', 
                array(&$this, 'settings_field_textarea'), 
                'mailman_integration', 
                'mmi-list-settings-section',
                array(
                    'field' => 'mmi_mailing_lists_nonpublic',
                    'desc' => 'To handle a mailing list which is not publically listed, please enter it and its password here manually. The format should be </em><strong>title|listname|password</strong><em>, one list per line. The list name is usually its e-mail address with the @-sign replaced by an underscore.',
                    'placeholder' => 'List Title|listname_domain.tld|password',
                )
            );
78
        } 
79
        
80

81 82
        public function settings_section_mmi_list_settings()
        {
83
            echo 'To make this plugin work, you need to enter the URL to the public Mailman list page on the server where your mailing lists reside (will usually be something like http://your-domain.com/mailman/admin), choose which mailing lists you want to manage, and specify their admin passwords. If you can\'t see any selectable mailing lists below, please double-check that your admin URL is correct and hit "Refresh mailing lists".</p><p>Only <strong>publically listed</strong> mailing lists will show up automatically, so either make public any lists you want to manage in Mailman, or add them manually below. Please note that list passwords are stored in <strong>plaintext,</strong> unencrypted.';
84 85
        }
        
86
        
87 88 89 90 91 92 93 94 95
        public function settings_field_input_text($args)
        {
            // Get the field name from the $args array
            $field = $args['field'];
            // Get the value of this setting
            $value = get_option($field);

            $ph = isset($args['placeholder']) ? $args['placeholder'] : '';
            $desc = isset($args['desc']) ? $args['desc'] : '';
96 97
            $css = isset($args['style']) ? $args['style'] : '';

98
            echo '<input type="text" name="'.$field.'" id="'.$field.'" value="'.$value.'" style="width:99%;display:block;'.$css.'" placeholder="'.$ph.'"><em>'.$desc.'</em>';
99
        }
100 101 102 103 104 105 106 107 108 109 110 111


        public function settings_field_textarea($args)
        {
            // Get the field name from the $args array
            $field = $args['field'];
            // Get the value of this setting
            $value = get_option($field);

            $desc = isset($args['desc']) ? $args['desc'] : '';
            $rows = isset($args['rows']) ? $args['rows'] : 3;
            $ph = isset($args['placeholder']) ? $args['placeholder'] : '';
112
            $css = isset($args['style']) ? $args['style'] : '';
113

114 115
            echo '<textarea name="'.$field.'" id="'.$field.'" style="width:99%; display:block; '.$css.'" rows="'.$rows.'" placeholder="'.$ph.'">'.$value.'</textarea><em>'.$desc.'</em>';
        }
116 117 118 119 120 121
        
        /**
         * add a menu
         */		
        public function add_menu()
        {
122 123 124 125 126 127
            add_menu_page(
                'Mailman list handling', 
                'Mailing lists', 
                'publish_posts', 
                'mailman.php', 
                array(&$this, 'plugin_settings_page_check_lists'),
128 129
                'dashicons-email-alt',
                71
130
            );
131 132 133

            add_submenu_page(
                'mailman.php',
134
                'Mailman moderation queue', 
135
                'Moderation queues', 
136
                'publish_posts', 
137
                'mailman_queue', 
138 139
                array(&$this, 'plugin_settings_page_check_queue')
            );
140 141 142 143 144

            add_submenu_page(
                'mailman.php',
                'Mailman list settings',
                'Settings',
145 146
                'manage_options',
                'mailman_settings',
147 148
                array(&$this, 'plugin_settings_page_check')
            );
149
        } 
150 151 152 153 154 155 156 157 158 159 160 161 162
    
        /**
         * Menu Callbacks
         */		
        public function plugin_settings_page_check()
        {
        	if(!current_user_can('manage_options'))
        	{
        		wp_die(__('You do not have sufficient permissions to access this page.'));
        	}
	
        	// Render the settings template
        	include(sprintf("%s/templates/settings.php", dirname(__FILE__)));
163
        } 
164 165
        public function plugin_settings_page_check_lists()
        {
166
            if(!current_user_can('publish_posts'))
167 168 169 170 171 172
            {
                wp_die(__('You do not have sufficient permissions to access this page.'));
            }
    
            // Render the settings template
            include(sprintf("%s/templates/settings-lists.php", dirname(__FILE__)));
173 174 175
        }
        public function plugin_settings_page_check_queue()
        {
176
            if(!current_user_can('publish_posts'))
177 178 179 180 181 182 183
            {
                wp_die(__('You do not have sufficient permissions to access this page.'));
            }
    
            // Render the settings template
            include(sprintf("%s/templates/settings-queue.php", dirname(__FILE__)));
        }
184 185 186

    } // END class Mailman_Integration_Settings
} // END if(!class_exists('Mailman_Integration_Settings'))