Exemplo n.º 1
0
 public static function get_fields()
 {
     if (empty(self::$fields)) {
         $fields = array('notifications' => array('title' => esc_html__('Notifications', 'stream-notifications'), 'fields' => array(array('name' => 'role_access', 'title' => esc_html__('Role Access', 'stream-notifications'), 'type' => 'multi_checkbox', 'desc' => esc_html__('Users from the selected roles above will have permission to view, create and edit Stream Notifications. However, only site Administrators can access Stream Notifications Settings.', 'stream-notifications'), 'choices' => WP_Stream_Settings::get_roles(), 'default' => array('administrator')), array('name' => 'export_rules', 'title' => esc_html__('Export Rules', 'stream'), 'type' => 'link', 'href' => add_query_arg(array('action' => 'wp_stream_notifications_export', 'stream_notifications_nonce' => wp_create_nonce('stream-notifications-nonce')), admin_url('admin-ajax.php')), 'desc' => esc_html__('Export all rules to a JSON file.', 'stream-notifications'), 'default' => 0), array('name' => 'import_rules', 'title' => esc_html__('Import Rules', 'stream-notifications'), 'type' => 'file', 'href' => add_query_arg(array('action' => 'wp_stream_notifications_import', 'stream_notifications_nonce' => wp_create_nonce('stream-notifications-nonce')), admin_url('admin-ajax.php')), 'desc' => esc_html__('Import rules from a JSON file.', 'stream-notifications'), 'default' => 0))));
         self::$fields = apply_filters('wp_stream_notifications_options_fields', $fields);
     }
     return self::$fields;
 }
Exemplo n.º 2
0
 public static function get_fields()
 {
     if (empty(self::$fields)) {
         $fields = array('reports' => array('title' => __('Reports', 'stream-reports'), 'fields' => array(array('name' => 'role_access', 'title' => __('Role Access', 'stream-reports'), 'type' => 'multi_checkbox', 'desc' => __('Users from the selected roles above will have permission to view and edit Stream Reports. However, only site Administrators can access Stream Reports Settings.', 'stream-reports'), 'choices' => WP_Stream_Settings::get_roles(), 'default' => array('administrator')))));
         self::$fields = apply_filters('wp_stream_reports_options_fields', $fields);
     }
     return self::$fields;
 }
 /**
  * Public constructor
  *
  * @return void
  */
 public static function load()
 {
     self::$option_key = self::get_option_key();
     self::$options = self::get_options();
     // Register settings, and fields
     add_action('admin_init', array(__CLASS__, 'register_settings'));
     // Check if we need to flush rewrites rules
     add_action('update_option_' . self::OPTION_KEY, array(__CLASS__, 'updated_option_trigger_flush_rules'), 10, 2);
     add_filter('wp_stream_serialized_labels', array(__CLASS__, 'get_settings_translations'));
     // Ajax callback function to search users
     add_action('wp_ajax_stream_get_users', array(__CLASS__, 'get_users'));
     // Ajax callback function to search IPs
     add_action('wp_ajax_stream_get_ips', array(__CLASS__, 'get_ips'));
 }
    /**
     * Render settings page
     *
     * @return void
     */
    public static function render_settings_page()
    {
        $option_key = WP_Stream_Settings::$option_key;
        $form_action = apply_filters('wp_stream_settings_form_action', admin_url('options.php'));
        $page_title = apply_filters('wp_stream_settings_form_title', get_admin_page_title());
        $page_description = apply_filters('wp_stream_settings_form_description', '');
        $sections = WP_Stream_Settings::get_fields();
        $active_tab = wp_stream_filter_input(INPUT_GET, 'tab');
        wp_enqueue_script('stream-settings', plugins_url('../ui/js/settings.js', __FILE__), array('jquery'), WP_Stream::VERSION, true);
        ?>
		<div class="wrap">
			<h2><?php 
        echo esc_html($page_title);
        ?>
</h2>

			<?php 
        if (!empty($page_description)) {
            ?>
				<p><?php 
            echo esc_html($page_description);
            ?>
</p>
			<?php 
        }
        ?>

			<?php 
        settings_errors();
        ?>

			<?php 
        if (count($sections) > 1) {
            ?>
				<h2 class="nav-tab-wrapper">
					<?php 
            $i = 0;
            ?>
					<?php 
            foreach ($sections as $section => $data) {
                ?>
						<?php 
                $i++;
                ?>
						<?php 
                $is_active = 1 === $i && !$active_tab || $active_tab === $section;
                ?>
						<a href="<?php 
                echo esc_url(add_query_arg('tab', $section));
                ?>
" class="nav-tab<?php 
                if ($is_active) {
                    echo esc_attr(' nav-tab-active');
                }
                ?>
">
							<?php 
                echo esc_html($data['title']);
                ?>
						</a>
					<?php 
            }
            ?>
				</h2>
			<?php 
        }
        ?>

			<div class="nav-tab-content" id="tab-content-settings">
				<form method="post" action="<?php 
        echo esc_attr($form_action);
        ?>
" enctype="multipart/form-data">
					<div class="settings-sections">
		<?php 
        $i = 0;
        foreach ($sections as $section => $data) {
            $i++;
            $is_active = 1 === $i && !$active_tab || $active_tab === $section;
            if ($is_active) {
                settings_fields($option_key);
                do_settings_sections($option_key);
            }
        }
        ?>
					</div>
					<?php 
        submit_button();
        ?>
				</form>
			</div>
		</div>
	<?php 
    }
Exemplo n.º 5
0
 /**
  * Function will add excluded settings args into stream query
  *
  * @param $args array query args passed to stream_query
  *
  * @return array
  */
 public static function add_excluded_record_args($args)
 {
     // Remove record of excluded connector
     $args['connector__not_in'] = WP_Stream_Settings::get_excluded_by_key('connectors');
     // Remove record of excluded context
     $args['context__not_in'] = WP_Stream_Settings::get_excluded_by_key('contexts');
     // Remove record of excluded actions
     $args['action__not_in'] = WP_Stream_Settings::get_excluded_by_key('actions');
     // Remove record of excluded author
     $args['author__not_in'] = WP_Stream_Settings::get_excluded_by_key('authors');
     // Remove record of excluded author role
     $args['author_role__not_in'] = WP_Stream_Settings::get_excluded_by_key('roles');
     // Remove record of excluded ip
     $args['ip__not_in'] = WP_Stream_Settings::get_excluded_by_key('ip_addresses');
     return $args;
 }
Exemplo n.º 6
0
 public static function purge_scheduled_action()
 {
     global $wpdb;
     // Don't purge if in Network Admin if Stream isn't network enabled
     if (is_network_admin() && is_multisite() && !is_plugin_active_for_network(WP_STREAM_PLUGIN)) {
         return;
     }
     if (is_multisite() && is_plugin_active_for_network(WP_STREAM_PLUGIN)) {
         $options = (array) get_site_option(WP_Stream_Settings::NETWORK_KEY, array());
     } else {
         $options = WP_Stream_Settings::get_options();
     }
     $days = $options['general_records_ttl'];
     $date = new DateTime('now', $timezone = new DateTimeZone('UTC'));
     $date->sub(DateInterval::createFromDateString("{$days} days"));
     $where = $wpdb->prepare(' AND `stream`.`created` < %s', $date->format('Y-m-d H:i:s'));
     if (is_multisite() && !is_plugin_active_for_network(WP_STREAM_PLUGIN)) {
         $where .= $wpdb->prepare(' AND `blog_id` = %d', get_current_blog_id());
     }
     $wpdb->query($wpdb->prepare("DELETE `stream`, `context`, `meta`\n\t\t\t\tFROM {$wpdb->stream} AS `stream`\n\t\t\t\tLEFT JOIN {$wpdb->streamcontext} AS `context`\n\t\t\t\tON `context`.`record_id` = `stream`.`ID`\n\t\t\t\tLEFT JOIN {$wpdb->streammeta} AS `meta`\n\t\t\t\tON `meta`.`record_id` = `stream`.`ID`\n\t\t\t\tWHERE `stream`.`type` = %s\n\t\t\t\t{$where};", 'stream', $date->format('Y-m-d H:i:s')));
 }
 /**
  * Wrapper for the settings API to work on the network settings page
  */
 function network_options_action()
 {
     $allowed_referers = array(self::NETWORK_SETTINGS_PAGE_SLUG, self::DEFAULT_SETTINGS_PAGE_SLUG);
     if (!isset($_GET['action']) || !in_array($_GET['action'], $allowed_referers)) {
         return;
     }
     $options = isset($_POST['option_page']) ? explode(',', stripslashes($_POST['option_page'])) : null;
     if ($options) {
         foreach ($options as $option) {
             $option = trim($option);
             $value = null;
             $sections = WP_Stream_Settings::get_fields();
             foreach ($sections as $section_name => $section) {
                 foreach ($section['fields'] as $field_idx => $field) {
                     $option_key = $section_name . '_' . $field['name'];
                     if (isset($_POST[$option][$option_key])) {
                         $value[$option_key] = $_POST[$option][$option_key];
                     } else {
                         $value[$option_key] = false;
                     }
                 }
             }
             if (!is_array($value)) {
                 $value = trim($value);
             }
             update_site_option($option, $value);
         }
     }
     if (!count(get_settings_errors())) {
         add_settings_error('general', 'settings_updated', __('Settings saved.', 'default'), 'updated');
     }
     set_transient('wp_stream_settings_errors', get_settings_errors(), 30);
     $go_back = add_query_arg('settings-updated', 'true', wp_get_referer());
     wp_redirect($go_back);
     exit;
 }
 /**
  * Return settings fields
  *
  * @return array Multidimensional array of fields
  */
 public static function get_fields()
 {
     $fields = array('general' => array('title' => esc_html__('General', 'stream'), 'fields' => array(array('name' => 'role_access', 'title' => esc_html__('Role Access', 'stream'), 'type' => 'multi_checkbox', 'desc' => esc_html__('Users from the selected roles above will have permission to view Stream Records. However, only site Administrators can access Stream Settings.', 'stream'), 'choices' => self::get_roles(), 'default' => array('administrator')), array('name' => 'private_feeds', 'title' => esc_html__('Private Feeds', 'stream'), 'type' => 'checkbox', 'desc' => sprintf(__('Users from the selected roles above will be given a private key found in their %suser profile%s to access feeds of Stream Records securely. Please %sflush rewrite rules%s on your site after changing this setting.', 'stream'), sprintf('<a href="%s" title="%s">', admin_url(sprintf('profile.php#wp-stream-highlight:%s', WP_Stream_Feeds::USER_FEED_OPTION_KEY)), esc_attr__('View Profile', 'stream')), '</a>', sprintf('<a href="%s" title="%s" target="_blank">', esc_url('http://codex.wordpress.org/Rewrite_API/flush_rules#What_it_does'), esc_attr__('View Codex', 'stream')), '</a>'), 'after_field' => esc_html__('Enabled', 'stream'), 'default' => 0))), 'exclude' => array('title' => esc_html__('Exclude', 'stream'), 'fields' => array(array('name' => 'rules', 'title' => esc_html__('Exclude Rules', 'stream'), 'type' => 'rule_list', 'desc' => esc_html__('Create rules for excluding certain kinds of records from appearing in Stream.', 'stream'), 'default' => array(), 'nonce' => 'stream_get_ips'))), 'advanced' => array('title' => esc_html__('Advanced', 'stream'), 'fields' => array(array('name' => 'comment_flood_tracking', 'title' => esc_html__('Comment Flood Tracking', 'stream'), 'type' => 'checkbox', 'desc' => __('WordPress will automatically prevent duplicate comments from flooding the database. By default, Stream does not track these attempts unless you opt-in here. Enabling this is not necessary or recommended for most sites.', 'stream'), 'after_field' => esc_html__('Enabled', 'stream'), 'default' => 0))));
     // If Akismet is active, allow Admins to opt-in to Akismet tracking
     if (class_exists('Akismet')) {
         $akismet_tracking = array('name' => 'akismet_tracking', 'title' => esc_html__('Akismet Tracking', 'stream'), 'type' => 'checkbox', 'desc' => __('Akismet already keeps statistics for comment attempts that it blocks as SPAM. By default, Stream does not track these attempts unless you opt-in here. Enabling this is not necessary or recommended for most sites.', 'stream'), 'after_field' => esc_html__('Enabled', 'stream'), 'default' => 0);
         array_push($fields['advanced']['fields'], $akismet_tracking);
     }
     // If WP Cron is enabled, allow Admins to opt-in to WP Cron tracking
     if (wp_stream_is_wp_cron_enabled()) {
         $wp_cron_tracking = array('name' => 'wp_cron_tracking', 'title' => esc_html__('WP Cron Tracking', 'stream'), 'type' => 'checkbox', 'desc' => __('By default, Stream does not track activity performed by WordPress cron events unless you opt-in here. Enabling this is not necessary or recommended for most sites.', 'stream'), 'after_field' => esc_html__('Enabled', 'stream'), 'default' => 0);
         array_push($fields['advanced']['fields'], $wp_cron_tracking);
     }
     /**
      * Filter allows for modification of options fields
      *
      * @return array  Array of option fields
      */
     self::$fields = apply_filters('wp_stream_settings_option_fields', $fields);
     // Sort option fields in each tab by title ASC
     foreach (self::$fields as $tab => $options) {
         $titles = wp_list_pluck(self::$fields[$tab]['fields'], 'title');
         array_multisort($titles, SORT_ASC, self::$fields[$tab]['fields']);
     }
     return self::$fields;
 }
Exemplo n.º 9
0
 /**
  * Assembles records for display in search filters
  *
  * Gathers list of all authors/connectors, then compares it to
  * results of existing records.  All items that do not exist in records
  * get assigned a disabled value of "true".
  *
  * @uses   wp_stream_existing_records (see query.php)
  * @since  1.0.4
  *
  * @param  string  Column requested
  * @param  string  Table to be queried
  *
  * @return array   options to be displayed in search filters
  */
 function assemble_records($column, $table = '')
 {
     $setting_key = self::get_column_excluded_setting_key($column);
     $exclude_hide_previous_records = isset(WP_Stream_Settings::$options['exclude_hide_previous_records']) ? WP_Stream_Settings::$options['exclude_hide_previous_records'] : 0;
     /**
      * Toggle visibility of disabled connectors/actions/contexts on list table filter dropdown
      *
      * @param bool $hidden Visibility status, default is Hide Previous Record value set in Exclude setting.
      */
     $hide_disabled_column_filter = apply_filters('wp_stream_list_table_hide_disabled_ ' . $setting_key, 0 === $exclude_hide_previous_records ? false : true);
     // @todo eliminate special condition for authors, especially using a WP_User object as the value; should use string or stringifiable object
     if ('author' === $column) {
         require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
         $all_records = array();
         // If the number of users exceeds the max authors constant value then return an empty array and use AJAX instead
         $user_count = count_users();
         $total_users = $user_count['total_users'];
         if ($total_users > WP_Stream_Admin::PRELOAD_AUTHORS_MAX) {
             return array();
         }
         $authors = array_map(function ($user_id) {
             return new WP_Stream_Author($user_id);
         }, get_users(array('fields' => 'ID')));
         $authors[] = new WP_Stream_Author(0, array('is_wp_cli' => true));
         if ($hide_disabled_column_filter) {
             $excluded_records = WP_Stream_Settings::get_excluded_by_key($setting_key);
         }
         foreach ($authors as $author) {
             if ($hide_disabled_column_filter && in_array($author->id, $excluded_records)) {
                 continue;
             }
             $all_records[$author->id] = $author->get_display_name();
         }
     } else {
         $prefixed_column = sprintf('stream_%s', $column);
         $all_records = WP_Stream_Connectors::$term_labels[$prefixed_column];
         if (true === $hide_disabled_column_filter) {
             $excluded_records = WP_Stream_Settings::get_excluded_by_key($setting_key);
             foreach (array_keys($all_records) as $_connector) {
                 if (in_array($_connector, $excluded_records)) {
                     unset($all_records[$_connector]);
                 }
             }
         }
     }
     $existing_records = wp_stream_existing_records($column, $table);
     $active_records = array();
     $disabled_records = array();
     foreach ($all_records as $record => $label) {
         if (array_key_exists($record, $existing_records)) {
             $active_records[$record] = array('label' => $label, 'disabled' => '');
         } else {
             $disabled_records[$record] = array('label' => $label, 'disabled' => 'disabled="disabled"');
         }
     }
     // Remove WP-CLI pseudo user if no records with user=0 exist
     if (isset($disabled_records[0])) {
         unset($disabled_records[0]);
     }
     $sort = function ($a, $b) use($column) {
         $label_a = (string) $a['label'];
         $label_b = (string) $b['label'];
         if ($label_a === $label_b) {
             return 0;
         }
         return strtolower($label_a) < strtolower($label_b) ? -1 : 1;
     };
     uasort($active_records, $sort);
     uasort($disabled_records, $sort);
     // Not using array_merge() in order to preserve the array index for the Authors dropdown which uses the user_id as the key
     $all_records = $active_records + $disabled_records;
     return $all_records;
 }
 /**
  * Add action links to Stream drop row in admin list screen
  *
  * @filter wp_stream_action_links_{connector}
  *
  * @param  array  $links     Previous links registered
  * @param  object $record    Stream record
  *
  * @return array             Action links
  */
 public static function action_links($links, $record)
 {
     $context_labels = self::get_context_labels();
     $rules = array('stream' => array('menu_slug' => 'wp_stream', 'submenu_slug' => WP_Stream_Admin::SETTINGS_PAGE_SLUG, 'url' => function ($rule, $record) {
         $option_key = wp_stream_get_meta($record, 'option_key', true);
         $url_tab = null;
         if ('' !== $option_key) {
             foreach (WP_Stream_Settings::get_fields() as $tab_name => $tab_properties) {
                 foreach ($tab_properties['fields'] as $field) {
                     $field_key = sprintf('%s_%s', $tab_name, $field['name']);
                     if ($field_key === $option_key) {
                         $url_tab = $tab_name;
                         break 2;
                     }
                 }
             }
         }
         return add_query_arg(array('page' => $rule['submenu_slug'], 'tab' => $url_tab), admin_url('admin.php'));
     }, 'applicable' => function ($submenu, $record) {
         return $record->context === 'wp_stream';
     }), 'background_header' => array('menu_slug' => 'themes.php', 'submenu_slug' => function ($record) {
         return str_replace('_', '-', $record->context);
     }, 'url' => function ($rule, $record) {
         return add_query_arg('page', $rule['submenu_slug']($record), admin_url($rule['menu_slug']));
     }, 'applicable' => function ($submenu, $record) {
         return in_array($record->context, array('custom_header', 'custom_background'));
     }), 'general' => array('menu_slug' => 'options-general.php', 'submenu_slug' => function ($record) {
         return sprintf('options-%s.php', $record->context);
     }, 'url' => function ($rule, $record) {
         return admin_url($rule['submenu_slug']($record));
     }, 'applicable' => function ($submenu, $record) {
         return !empty($submenu['options-general.php']);
     }), 'network' => array('menu_slug' => 'settings.php', 'submenu_slug' => function ($record) {
         return 'settings.php';
     }, 'url' => function ($rule, $record) {
         return network_admin_url($rule['menu_slug']);
     }, 'applicable' => function ($submenu, $record) {
         if (!$record->blog_id) {
             return !empty($submenu['settings.php']);
         }
         return false;
     }));
     if ('settings' !== $record->context && in_array($record->context, array_keys($context_labels))) {
         global $submenu;
         $applicable_rules = array_filter($rules, function ($rule) use($submenu, $record) {
             return call_user_func($rule['applicable'], $submenu, $record);
         });
         if (!empty($applicable_rules)) {
             // The first applicable rule wins
             $rule = array_shift($applicable_rules);
             $menu_slug = $rule['menu_slug'];
             $submenu_slug = is_object($rule['submenu_slug']) && $rule['submenu_slug'] instanceof Closure ? $rule['submenu_slug']($record) : $rule['submenu_slug'];
             $url = $rule['url']($rule, $record);
             if (isset($submenu[$menu_slug])) {
                 $found_submenus = wp_list_filter($submenu[$menu_slug], array(2 => $submenu_slug));
             }
             if (!empty($found_submenus)) {
                 $target_submenu = array_pop($found_submenus);
                 list($menu_title, $capability) = $target_submenu;
                 if (current_user_can($capability)) {
                     $url = apply_filters('wp_stream_action_link_url', $url, $record);
                     $text = sprintf(__('Edit %s Settings', 'stream'), $context_labels[$record->context]);
                     $field_name = wp_stream_get_meta($record, 'option_key', true);
                     if ('' === $field_name) {
                         $field_name = wp_stream_get_meta($record, 'option', true);
                     }
                     if ('' !== $field_name) {
                         $url = sprintf('%s#%s%s', rtrim(preg_replace('/#.*/', '', $url), '/'), self::HIGHLIGHT_FIELD_URL_HASH_PREFIX, $field_name);
                     }
                     $links[$text] = $url;
                 }
             }
         }
     }
     return $links;
 }
Exemplo n.º 11
0
 /**
  * This function is use to check whether logging is enabled
  *
  * @param $column string name of the setting key (actions|ip_addresses|contexts|connectors)
  * @param $value string to check in excluded array
  * @return array
  */
 public static function is_logging_enabled($column, $value)
 {
     $excluded_values = WP_Stream_Settings::get_excluded_by_key($column);
     $bool = !in_array($value, $excluded_values);
     return $bool;
 }
Exemplo n.º 12
0
/**
 * @param $labels array connectors terms labels
 *
 * @action wp_stream_after_connectors_registration
 * @return string $current_version if updated correctly
 */
function wp_stream_update_migrate_old_options_to_exclude_tab($labels)
{
    global $wpdb;
    $db_version = WP_Stream_Install::$db_version;
    $current_version = WP_Stream_Install::$current;
    do_action('wp_stream_before_db_update_' . $db_version, $current_version);
    $old_options = get_option(WP_Stream_Settings::KEY, array());
    // Stream > Settings > General > Log Activity for
    if (isset($old_options['general_log_activity_for'])) {
        WP_Stream_Settings::$options['exclude_authors_and_roles'] = array_diff(array_keys(WP_Stream_Settings::get_roles()), $old_options['general_log_activity_for']);
        unset(WP_Stream_Settings::$options['general_log_activity_for']);
    }
    // Stream > Settings > Connectors > Active Connectors
    if (isset($old_options['connectors_active_connectors'])) {
        WP_Stream_Settings::$options['exclude_connectors'] = array_diff(array_keys($labels), $old_options['connectors_active_connectors']);
        unset(WP_Stream_Settings::$options['connectors_active_connectors']);
    }
    update_option(WP_Stream_Settings::KEY, WP_Stream_Settings::$options);
    do_action('wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error);
    if ($wpdb->last_error) {
        return false;
    }
    return $current_version;
}
Exemplo n.º 13
0
 /**
  * Uses network options when on the network settings page
  *
  * @param $options
  *
  * @return array
  */
 function get_network_options($options, $option_key)
 {
     if (is_network_admin()) {
         $options = wp_parse_args((array) get_site_option($option_key, array()), WP_Stream_Settings::get_defaults($option_key));
     }
     return $options;
 }