Esempio n. 1
0
 public static function export()
 {
     if (!wp_verify_nonce(wp_stream_filter_input(INPUT_GET, 'stream_notifications_nonce'), 'stream-notifications-nonce')) {
         wp_die(__('Invalid nonce, go back and try again.', 'stream-notifications'));
     }
     $args = array('type' => 'notification_rule', 'ignore_context' => true, 'posts_per_page' => -1, 'order' => 'asc');
     $query = wp_stream_query($args);
     $items = array();
     $cached = get_transient('stream-notification-rules');
     foreach ($query as $rule) {
         $rule = new WP_Stream_Notification_Rule($rule->ID);
         $rule->ID = null;
         $items[] = $rule->to_array();
     }
     $json = json_encode($items);
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="stream-notification-rules_' . current_time('timestamp', 1) . '.json"');
     header('Connection: Keep-Alive');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Length: ' . strlen($json));
     echo $json;
     // xss ok
     die;
 }
Esempio n. 2
0
 /**
  * Check if a log if send to the DB when we delete a post
  *
  * @return void
  */
 public function test_delete_post_log()
 {
     //Create a post
     $post_id = $this->factory->post->create();
     //Delete the post
     wp_delete_post($post_id, true);
     //Test the
     $this->assertGreaterThan(0, did_action($this->action_prefix . 'callback_deleted_post'));
     //Check if the entry is in the database
     $result = wp_stream_query(array('object_id' => $post_id, 'context' => 'post', 'action' => 'deleted'));
     //Check if the DB entry is okay
     $this->assertEquals(1, count($result));
 }
    /**
     * Contents of the Stream Activity dashboard widget
     */
    public static function stream_activity_contents($paged = 1)
    {
        $options = get_option('dashboard_stream_activity_options', array());
        $records_per_page = isset($options['records_per_page']) ? absint($options['records_per_page']) : 5;
        $args = array('records_per_page' => $records_per_page, 'paged' => $paged);
        $records = wp_stream_query($args);
        $total_items = WP_Stream::$db->get_found_rows();
        if (!$records) {
            ?>
			<p class="no-records"><?php 
            esc_html_e('Sorry, no activity records were found.', 'stream');
            ?>
</p>
			<?php 
            return;
        }
        printf('<ul>%s</ul>', implode('', array_map(array(__CLASS__, 'widget_row'), $records)));
        $args = array('current' => $paged, 'total_pages' => absint(ceil($total_items / $records_per_page)));
        self::pagination($args);
    }
Esempio n. 4
0
 /**
  * Filter the predefined intervals to reflect db oldest value
  * @param $intervals
  *
  * @return array
  */
 public function filter_predefined_intervals($intervals)
 {
     $query = wp_stream_query(array('order' => 'ASC', 'orderby' => 'created', 'records_per_page' => 1, 'ignore_context' => true));
     $first_stream_item = reset($query);
     if (false === $first_stream_item) {
         return array();
     }
     $first_stream_date = \Carbon\Carbon::parse($first_stream_item->created);
     foreach ($intervals as $key => $interval) {
         if (!isset($interval['start']) || false === $interval['start']) {
             $intervals[$key]['start'] = $interval['start'] = $first_stream_date;
         }
         if (!isset($interval['end']) || false === $interval['end']) {
             $intervals[$key]['end'] = $interval['end'] = \Carbon\Carbon::now();
         }
         if (!is_a($interval['start'], '\\Carbon\\Carbon') || !is_a($interval['end'], '\\Carbon\\Carbon')) {
             unset($intervals[$key]);
             continue;
         }
     }
     return $intervals;
 }
 public function rules($force_refresh = false)
 {
     # DEBUG
     $force_refresh = true;
     // Check if we have a valid cache
     if (!$force_refresh && false !== ($rules = get_transient(self::CACHE_KEY))) {
         return $rules;
     }
     // Get rules
     $args = array('type' => 'notification_rule', 'ignore_context' => true, 'records_per_page' => -1, 'fields' => 'ID', 'visibility' => 'active');
     $rules = wp_stream_query($args);
     if (is_multisite() && is_plugin_active_for_network(WP_STREAM_NOTIFICATIONS_PLUGIN)) {
         $args = array('blog_id' => '0', 'type' => 'notification_rule', 'ignore_context' => true, 'records_per_page' => -1, 'fields' => 'ID', 'visibility' => 'active');
         $network_rules = wp_stream_query($args);
         $rules = array_merge($rules, $network_rules);
     }
     $rules = wp_list_pluck($rules, 'ID');
     $rules = $this->format($rules);
     // Cache the new rules
     set_transient(self::CACHE_KEY, $rules);
     return $rules;
 }
 /**
  * Gets existing records for filtering dropdown menus
  *
  * @return array
  */
 function get_existing_records()
 {
     $existing_records = array();
     $args = array('aggregations' => array('connector', 'context', 'action'));
     $query = wp_stream_query($args);
     $query_meta = WP_Stream::$db->get_query_meta();
     if (isset($query_meta->aggregations)) {
         foreach ($query_meta->aggregations as $field => $aggregation) {
             $existing_records[$field] = array();
             foreach ($aggregation->buckets as $bucket) {
                 $existing_records[$field][] = $bucket->key;
             }
         }
     }
     return $existing_records;
 }
 /**
  * Plugin activation routine
  * @return void
  */
 public function on_activation()
 {
     // Add sample rule
     if (function_exists('wp_stream_query') && !wp_stream_query('type=notification_rule&ignore_context=1')) {
         $this->load();
         $this->add_sample_rule();
     }
 }
 function get_records()
 {
     $args = array();
     // Parse sorting params
     if ($order = wp_stream_filter_input(INPUT_GET, 'order')) {
         $args['order'] = $order;
     }
     if ($orderby = wp_stream_filter_input(INPUT_GET, 'orderby')) {
         $args['orderby'] = $orderby;
     }
     // Filters
     $params = array('search', 'date', 'date_from', 'date_to', 'record_after', 'date_after', 'date_before');
     foreach ($params as $param) {
         $value = wp_stream_filter_input(INPUT_GET, $param);
         if ($value) {
             $args[$param] = $value;
         }
     }
     // Additional filter properties
     $properties = array('record', 'author', 'author_role', 'ip', 'object_id', 'site_id', 'blog_id', 'connector', 'context', 'action');
     // Add property fields to defaults, including their __in/__not_in variations
     foreach ($properties as $property) {
         $value = wp_stream_filter_input(INPUT_GET, $property);
         // Allow 0 values
         if (isset($value) && '' !== $value && false !== $value) {
             $args[$property] = $value;
         }
         $value_in = wp_stream_filter_input(INPUT_GET, $property . '__in');
         if ($value_in) {
             $args[$property . '__in'] = explode(',', $value_in);
         }
         $value_not_in = wp_stream_filter_input(INPUT_GET, $property . '__not_in');
         if ($value_not_in) {
             $args[$property . '__not_in'] = explode(',', $value_not_in);
         }
     }
     $args['paged'] = $this->get_pagenum();
     if (isset($args['context']) && 0 === strpos($args['context'], 'group-')) {
         $args['connector'] = str_replace('group-', '', $args['context']);
         $args['context'] = '';
     }
     if (!isset($args['records_per_page'])) {
         $args['records_per_page'] = $this->get_items_per_page('edit_stream_per_page', 20);
     }
     $args['aggregations'] = array('author', 'connector', 'context', 'action');
     $items = wp_stream_query($args);
     return $items;
 }
 public function get_stream()
 {
     // Filters
     $allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
     $sections = isset($_POST['sections']) ? unserialize(base64_decode($_POST['sections'])) : array();
     if (!is_array($sections)) {
         $sections = array();
     }
     //return $sections;
     $other_tokens = isset($_POST['other_tokens']) ? unserialize(base64_decode($_POST['other_tokens'])) : array();
     if (!is_array($other_tokens)) {
         $other_tokens = array();
     }
     //return $other_tokens;
     unset($_POST['sections']);
     unset($_POST['other_tokens']);
     $args = array();
     foreach ($allowed_params as $param) {
         if (self::$mainwpChildReports) {
             $paramval = mainwp_wp_stream_filter_input(INPUT_POST, $param);
         } else {
             $paramval = wp_stream_filter_input(INPUT_POST, $param);
         }
         if ($paramval || '0' === $paramval) {
             $args[$param] = $paramval;
         }
     }
     foreach ($args as $arg => $val) {
         if (!in_array($arg, $allowed_params)) {
             unset($args[$arg]);
         }
     }
     $args['action__not_in'] = array('login');
     $args['fields'] = 'with-meta';
     if (isset($args['date_from'])) {
         $args['date_from'] = date("Y-m-d H:i:s", $args['date_from']);
     }
     if (isset($args['date_to'])) {
         $args['date_to'] = date("Y-m-d H:i:s", $args['date_to']);
     }
     $args['records_per_page'] = 9999;
     //        error_log(print_r($args, true));
     if (self::$mainwpChildReports) {
         $records = mainwp_wp_stream_query($args);
     } else {
         $records = wp_stream_query($args);
     }
     //        if (count($records) > 0)
     //            error_log(print_r($records, true));
     //        else
     //            error_log("==============");
     if (!is_array($records)) {
         $records = array();
     }
     //return $records;
     //$other_tokens_data = $this->get_other_tokens_data($records, $other_tokens);
     if (isset($other_tokens['header']) && is_array($other_tokens['header'])) {
         $other_tokens_data['header'] = $this->get_other_tokens_data($records, $other_tokens['header']);
     }
     if (isset($other_tokens['body']) && is_array($other_tokens['body'])) {
         $other_tokens_data['body'] = $this->get_other_tokens_data($records, $other_tokens['body']);
     }
     if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) {
         $other_tokens_data['footer'] = $this->get_other_tokens_data($records, $other_tokens['footer']);
     }
     $sections_data = array();
     if (isset($sections['header']) && is_array($sections['header']) && !empty($sections['header'])) {
         foreach ($sections['header']['section_token'] as $index => $sec) {
             $tokens = $sections['header']['section_content_tokens'][$index];
             $sections_data['header'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['body']) && is_array($sections['body']) && !empty($sections['body'])) {
         foreach ($sections['body']['section_token'] as $index => $sec) {
             $tokens = $sections['body']['section_content_tokens'][$index];
             $sections_data['body'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['footer']) && is_array($sections['footer']) && !empty($sections['footer'])) {
         foreach ($sections['footer'] as $index => $sec) {
             $tokens = $sections['footer']['section_content_tokens'][$index];
             $sections_data['footer'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     $information = array('other_tokens_data' => $other_tokens_data, 'sections_data' => $sections_data);
     return $information;
 }
Esempio n. 10
0
    /**
     * Output for Stream Records as a feed.
     *
     * @return xml
     */
    public static function feed_template()
    {
        $die_title = esc_html__('Access Denied', 'stream');
        $die_message = '<h1>' . $die_title . '</h1><p>' . esc_html__('You don\'t have permission to view this feed, please contact your site Administrator.', 'stream') . '</p>';
        if (!isset($_GET[self::FEED_QUERY_VAR]) || empty($_GET[self::FEED_QUERY_VAR])) {
            wp_die($die_message, $die_title);
        }
        $args = array('meta_key' => self::USER_FEED_KEY, 'meta_value' => $_GET[self::FEED_QUERY_VAR], 'number' => 1);
        $user = get_users($args);
        if (!is_super_admin($user[0]->ID)) {
            $roles = isset($user[0]->roles) ? (array) $user[0]->roles : array();
            if (self::$is_network_feed) {
                wp_die($die_message, $die_title);
            }
            if (!$roles || !array_intersect($roles, WP_Stream_Settings::$options['general_role_access'])) {
                wp_die($die_message, $die_title);
            }
        }
        $blog_id = self::$is_network_feed ? null : get_current_blog_id();
        $args = array('blog_id' => $blog_id, 'records_per_page' => wp_stream_filter_input(INPUT_GET, 'records_per_page', FILTER_SANITIZE_NUMBER_INT, array('options' => array('default' => get_option('posts_per_rss')))), 'search' => wp_stream_filter_input(INPUT_GET, 'search'), 'object_id' => wp_stream_filter_input(INPUT_GET, 'object_id', FILTER_SANITIZE_NUMBER_INT), 'ip' => wp_stream_filter_input(INPUT_GET, 'ip', FILTER_VALIDATE_IP), 'author' => wp_stream_filter_input(INPUT_GET, 'author', FILTER_SANITIZE_NUMBER_INT), 'author_role' => wp_stream_filter_input(INPUT_GET, 'author_role'), 'date' => wp_stream_filter_input(INPUT_GET, 'date'), 'date_from' => wp_stream_filter_input(INPUT_GET, 'date_from'), 'date_to' => wp_stream_filter_input(INPUT_GET, 'date_to'), 'record__in' => wp_stream_filter_input(INPUT_GET, 'record__in', FILTER_SANITIZE_NUMBER_INT), 'record_parent' => wp_stream_filter_input(INPUT_GET, 'record_parent', FILTER_SANITIZE_NUMBER_INT), 'order' => wp_stream_filter_input(INPUT_GET, 'order', FILTER_DEFAULT, array('options' => array('default' => 'desc'))), 'orderby' => wp_stream_filter_input(INPUT_GET, 'orderby', FILTER_DEFAULT, array('options' => array('default' => 'ID'))), 'fields' => wp_stream_filter_input(INPUT_GET, 'fields', FILTER_DEFAULT, array('options' => array('default' => 'with-meta'))));
        $records = wp_stream_query($args);
        $latest_record = isset($records[0]->created) ? $records[0]->created : null;
        $records_admin_url = add_query_arg(array('page' => WP_Stream_Admin::RECORDS_PAGE_SLUG), admin_url(WP_Stream_Admin::ADMIN_PARENT_PAGE));
        if ('json' === wp_stream_filter_input(INPUT_GET, self::FEED_TYPE_QUERY_VAR)) {
            if (version_compare(PHP_VERSION, '5.4', '>=')) {
                echo json_encode($records, JSON_PRETTY_PRINT);
            } else {
                echo json_encode($records);
            }
        } else {
            header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
            printf('<?xml version="1.0" encoding="%s"?>', esc_attr(get_option('blog_charset')));
            ?>

			<rss version="2.0"
				xmlns:content="http://purl.org/rss/1.0/modules/content/"
				xmlns:wfw="http://wellformedweb.org/CommentAPI/"
				xmlns:dc="http://purl.org/dc/elements/1.1/"
				xmlns:atom="http://www.w3.org/2005/Atom"
				xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
				xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
				<?php 
            /**
             * Action fires during RSS xmls printing
             */
            ?>
				<?php 
            do_action('rss2_ns');
            ?>
			>
				<channel>
					<title><?php 
            bloginfo_rss('name');
            ?>
 - <?php 
            esc_html_e('Stream Feed', 'stream');
            ?>
</title>
					<atom:link href="<?php 
            self_link();
            ?>
" rel="self" type="application/rss+xml" />
					<link><?php 
            echo esc_url($records_admin_url);
            ?>
</link>
					<description><?php 
            bloginfo_rss('description');
            ?>
</description>
					<lastBuildDate><?php 
            echo esc_html(mysql2date('r', $latest_record, false));
            ?>
</lastBuildDate>
					<language><?php 
            bloginfo_rss('language');
            ?>
</language>
					<sy:updatePeriod><?php 
            echo esc_html('hourly');
            ?>
</sy:updatePeriod>
					<sy:updateFrequency><?php 
            echo absint(1);
            ?>
</sy:updateFrequency>
					<?php 
            /**
             * Action fires during RSS head
             */
            ?>
					<?php 
            do_action('rss2_head');
            ?>
					<?php 
            foreach ($records as $record) {
                ?>
						<?php 
                $record_link = add_query_arg(array('record__in' => (int) $record->ID), $records_admin_url);
                $author = get_userdata($record->author);
                $display_name = isset($author->display_name) ? $author->display_name : 'N/A';
                ?>
						<item>
							<title><![CDATA[ <?php 
                echo trim($record->summary);
                ?>
 ]]></title>
							<pubDate><?php 
                echo esc_html(mysql2date('r', $record->created, false));
                ?>
</pubDate>
							<dc:creator><?php 
                echo esc_html($display_name);
                ?>
</dc:creator>
							<category domain="connector"><![CDATA[ <?php 
                echo esc_html($record->connector);
                ?>
 ]]></category>
							<category domain="context"><![CDATA[ <?php 
                echo esc_html($record->context);
                ?>
 ]]></category>
							<category domain="action"><![CDATA[ <?php 
                echo esc_html($record->action);
                ?>
 ]]></category>
							<category domain="ip"><?php 
                echo esc_html($record->ip);
                ?>
</category>
							<guid isPermaLink="false"><?php 
                echo esc_url($record_link);
                ?>
</guid>
							<link><?php 
                echo esc_url($record_link);
                ?>
</link>
							<?php 
                /**
                 * Action fires during RSS item
                 */
                ?>
							<?php 
                do_action('rss2_item');
                ?>
						</item>
					<?php 
            }
            ?>
				</channel>
			</rss>
			<?php 
            exit;
        }
    }
Esempio n. 11
0
 function get_records()
 {
     $args = array();
     // Parse sorting params
     if (!($order = wp_stream_filter_input(INPUT_GET, 'order'))) {
         $order = 'DESC';
     }
     if (!($orderby = wp_stream_filter_input(INPUT_GET, 'orderby'))) {
         $orderby = '';
     }
     $args['order'] = $order;
     $args['orderby'] = $orderby;
     // Filters
     $allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
     foreach ($allowed_params as $param) {
         $paramval = wp_stream_filter_input(INPUT_GET, $param);
         if ($paramval || '0' === $paramval) {
             $args[$param] = $paramval;
         }
     }
     $args['paged'] = $this->get_pagenum();
     if (!isset($args['records_per_page'])) {
         $args['records_per_page'] = $this->get_items_per_page('edit_stream_per_page', 20);
     }
     $items = wp_stream_query($args);
     return $items;
 }
Esempio n. 12
0
/**
 * stream_query()
 *
 * @deprecated 1.3.2
 * @deprecated Use wp_stream_query()
 * @see wp_stream_query()
 */
function stream_query($args = array())
{
    _deprecated_function(__FUNCTION__, '1.3.2', 'wp_stream_query()');
    return wp_stream_query($args);
}
Esempio n. 13
0
 /**
  * Sends Updated Actions to the List Table View
  *
  * @param       int    Timestamp of last update
  * @param array $query
  *
  * @return array  Array of recently updated items
  */
 public static function gather_updated_items($last_id, $query = array())
 {
     if (false === $last_id) {
         return '';
     }
     $default = array('record_greater_than' => (int) $last_id);
     // Filter default
     $query = wp_parse_args($query, $default);
     // Run query
     $items = wp_stream_query($query);
     return $items;
 }
Esempio n. 14
0
 /**
  * Checks for a Stream connection and displays an error or success message.
  *
  * @return void
  */
 private function connection()
 {
     $query = wp_stream_query(array('records_per_page' => 1, 'fields' => 'created'));
     if (!$query) {
         WP_CLI::error(__('SITE IS DISCONNECTED', 'stream'));
     }
 }
Esempio n. 15
0
/**
 * @action   wp_stream_after_connectors_registration
 * @return string $current_version if updated correctly
 */
function wp_stream_update_migrate_installer_edits_to_theme_editor_connector()
{
    global $wpdb;
    $db_version = WP_Stream_Install::$db_version;
    $current_version = WP_Stream_Install::$current;
    $args = array('connector' => 'installer', 'context' => 'themes', 'action' => 'edited');
    $records = wp_stream_query($args);
    foreach ($records as $record) {
        $file_name = wp_stream_get_meta($record->ID, 'file', true);
        $theme_name = wp_stream_get_meta($record->ID, 'name', true);
        if ('' !== $theme_name) {
            $matched_themes = array_filter(wp_get_themes(), function ($theme) use($theme_name) {
                return (string) $theme === $theme_name;
            });
            $theme = array_shift($matched_themes);
            // `stream`
            $wpdb->update($wpdb->stream, array('summary' => sprintf(WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name)), array('ID' => $record->ID));
            // `stream_context`
            $wpdb->update($wpdb->streamcontext, array('connector' => 'editor', 'context' => is_object($theme) ? $theme->get_template() : $theme_name, 'action' => 'updated'), array('record_id' => $record->ID));
            wp_stream_update_meta($record->ID, 'theme_name', $theme_name);
            if (is_object($theme)) {
                wp_stream_update_meta($record->ID, 'theme_slug', $theme->get_template());
            }
        }
    }
    do_action('wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error);
    if ($wpdb->last_error) {
        return false;
    }
    return $current_version;
}
Esempio n. 16
0
 public function load_metabox_records($args, $date_interval)
 {
     $query_args = array('records_per_page' => -1, 'date_from' => $date_interval['start'], 'date_to' => $date_interval['end']);
     switch ($args['data_group']) {
         case 'action':
             $query_args['action'] = $args['data_type'];
             break;
         case 'blog_id':
             $query_args['blog_id'] = $args['data_type'];
             break;
         case 'connector':
             $query_args['connector'] = $args['data_type'];
             break;
         case 'context':
             $query_args['context'] = $args['data_type'];
             break;
         case 'other':
             // all selector requires no query arg modifications
             break;
         default:
             return array();
     }
     $grouping_field = $args['selector_type'];
     $available_fields = array('author', 'author_role', 'action', 'context', 'connector', 'ip', 'blog_id');
     if (!in_array($grouping_field, $available_fields)) {
         return array();
     }
     $query_args = apply_filters('wp_stream_reports_query_args', $query_args, $args);
     $unsorted = wp_stream_query($query_args);
     if ('author_role' === $grouping_field) {
         foreach ($unsorted as $key => $record) {
             $user = get_userdata($record->author);
             if ($user) {
                 $record->author_role = join(',', $user->roles);
             } else {
                 if (0 === $record->author) {
                     $record->author_role = __('N/A', 'stream-reports');
                 } else {
                     $record->author_role = __('Unknown', 'stream-reports');
                 }
             }
         }
     }
     $sorted = $this->group_by_field($grouping_field, $unsorted);
     return $sorted;
 }
 /**
  * Get the unread count for the current user.
  *
  * Results are cached in transient with a 5 min TTL.
  *
  * @return int
  */
 public static function get_unread_count()
 {
     if (!self::unread_enabled_for_user()) {
         return false;
     }
     $user_id = get_current_user_id();
     $cache_key = sprintf('%s_%d', self::UNREAD_COUNT_OPTION_KEY, $user_id);
     if (false === ($count = get_transient($cache_key))) {
         $count = 0;
         $last_read = get_user_meta($user_id, self::LAST_READ_OPTION_KEY, true);
         if (!empty($last_read)) {
             $args = array('records_per_page' => 101, 'author__not_in' => array($user_id), 'date_after' => date('c', strtotime($last_read . ' + 1 second')), 'fields' => array('created'));
             $unread_records = wp_stream_query($args);
             $count = empty($unread_records) ? 0 : count($unread_records);
         }
         set_transient($cache_key, $count, 5 * 60);
         // TTL 5 min
     }
     return absint($count);
 }
 public function get_stream()
 {
     // Filters
     $allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
     $sections = isset($_POST['sections']) ? maybe_unserialize(base64_decode($_POST['sections'])) : array();
     if (!is_array($sections)) {
         $sections = array();
     }
     //return $sections;
     $other_tokens = isset($_POST['other_tokens']) ? maybe_unserialize(base64_decode($_POST['other_tokens'])) : array();
     if (!is_array($other_tokens)) {
         $other_tokens = array();
     }
     //return $other_tokens;
     unset($_POST['sections']);
     unset($_POST['other_tokens']);
     $args = array();
     foreach ($allowed_params as $param) {
         if (self::$mainwpChildReports) {
             $paramval = mainwp_wp_stream_filter_input(INPUT_POST, $param);
         } else {
             $paramval = wp_stream_filter_input(INPUT_POST, $param);
         }
         if ($paramval || '0' === $paramval) {
             $args[$param] = $paramval;
         }
     }
     foreach ($args as $arg => $val) {
         if (!in_array($arg, $allowed_params)) {
             unset($args[$arg]);
         }
     }
     // to fix bug
     $exclude_connector_posts = true;
     if (isset($sections['body']) && isset($sections['body']['section_token']) && is_array($sections['body']['section_token'])) {
         foreach ($sections['body']['section_token'] as $sec) {
             if (strpos($sec, "[section.posts") !== false) {
                 $exclude_connector_posts = false;
                 break;
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($sections['header']) && isset($sections['header']['section_token']) && is_array($sections['header']['section_token'])) {
             foreach ($sections['header']['section_token'] as $sec) {
                 if (strpos($sec, "[section.posts") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($sections['footer']) && isset($sections['footer']['section_token']) && is_array($sections['footer']['section_token'])) {
             foreach ($sections['footer']['section_token'] as $sec) {
                 if (strpos($sec, "[section.posts") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['body']) && is_array($other_tokens['body'])) {
             foreach ($other_tokens['body'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['header']) && is_array($other_tokens['header'])) {
             foreach ($other_tokens['header'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) {
             foreach ($other_tokens['footer'] as $sec) {
                 if (strpos($sec, "[post.") !== false) {
                     $exclude_connector_posts = false;
                     break;
                 }
             }
         }
     }
     if ($exclude_connector_posts) {
         $args['connector__not_in'] = array('posts');
     }
     ///// end fix /////
     $args['action__not_in'] = array('login');
     // fix for Stream 3
     if (3 !== self::$streamVersionNumber) {
         $args['fields'] = 'with-meta';
         if (isset($args['date_from'])) {
             $args['date_from'] = date('Y-m-d H:i:s', $args['date_from']);
         }
         if (isset($args['date_to'])) {
             $args['date_to'] = date('Y-m-d H:i:s', $args['date_to']);
         }
     } else {
         if (isset($args['date_from'])) {
             $args['date_from'] = date('Y-m-d', $args['date_from']);
         }
         if (isset($args['date_to'])) {
             $args['date_to'] = date('Y-m-d', $args['date_to']);
         }
     }
     $args['records_per_page'] = 9999;
     //        error_log(print_r($args, true));
     if (self::$mainwpChildReports) {
         $records = mainwp_wp_stream_query($args);
     } else {
         if (149 === self::$streamVersionNumber) {
             $records = wp_stream_query($args);
         } else {
             if (3 === self::$streamVersionNumber) {
                 $records = wp_stream_get_instance()->db->query->query($args);
             }
         }
     }
     if (!is_array($records)) {
         $records = array();
     }
     //return $records;
     //$other_tokens_data = $this->get_other_tokens_data($records, $other_tokens);
     if (isset($other_tokens['header']) && is_array($other_tokens['header'])) {
         $other_tokens_data['header'] = $this->get_other_tokens_data($records, $other_tokens['header']);
     }
     if (isset($other_tokens['body']) && is_array($other_tokens['body'])) {
         $other_tokens_data['body'] = $this->get_other_tokens_data($records, $other_tokens['body']);
     }
     if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) {
         $other_tokens_data['footer'] = $this->get_other_tokens_data($records, $other_tokens['footer']);
     }
     $sections_data = array();
     if (isset($sections['header']) && is_array($sections['header']) && !empty($sections['header'])) {
         foreach ($sections['header']['section_token'] as $index => $sec) {
             $tokens = $sections['header']['section_content_tokens'][$index];
             $sections_data['header'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['body']) && is_array($sections['body']) && !empty($sections['body'])) {
         foreach ($sections['body']['section_token'] as $index => $sec) {
             $tokens = $sections['body']['section_content_tokens'][$index];
             $sections_data['body'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     if (isset($sections['footer']) && is_array($sections['footer']) && !empty($sections['footer'])) {
         foreach ($sections['footer'] as $index => $sec) {
             $tokens = $sections['footer']['section_content_tokens'][$index];
             $sections_data['footer'][$index] = $this->get_section_loop_data($records, $tokens, $sec);
         }
     }
     $information = array('other_tokens_data' => $other_tokens_data, 'sections_data' => $sections_data);
     return $information;
 }
 /**
  * Output for Stream Records as a feed.
  *
  * @return xml
  */
 public static function feed_template()
 {
     $die_title = esc_html__('Access Denied', 'stream');
     $die_message = sprintf('<h1>%s</h1><p>%s</p>', $die_title, esc_html__("You don't have permission to view this feed, please contact your site Administrator.", 'stream'));
     $query_var = is_network_admin() ? self::FEED_NETWORK_QUERY_VAR : self::FEED_QUERY_VAR;
     $args = array('meta_key' => self::USER_FEED_OPTION_KEY, 'meta_value' => wp_stream_filter_input(INPUT_GET, self::FEED_KEY_QUERY_VAR), 'number' => 1);
     $user = get_users($args);
     if (empty($user)) {
         wp_die($die_message, $die_title);
     }
     if (!is_super_admin($user[0]->ID)) {
         $roles = isset($user[0]->roles) ? (array) $user[0]->roles : array();
         if (self::$is_network_feed) {
             wp_die($die_message, $die_title);
         }
         if (!$roles || !array_intersect($roles, WP_Stream_Settings::$options['general_role_access'])) {
             wp_die($die_message, $die_title);
         }
     }
     $blog_id = self::$is_network_feed ? null : get_current_blog_id();
     $args = array('blog_id' => $blog_id, 'records_per_page' => wp_stream_filter_input(INPUT_GET, 'records_per_page', FILTER_SANITIZE_NUMBER_INT), 'search' => wp_stream_filter_input(INPUT_GET, 'search'), 'object_id' => wp_stream_filter_input(INPUT_GET, 'object_id', FILTER_SANITIZE_NUMBER_INT), 'ip' => wp_stream_filter_input(INPUT_GET, 'ip', FILTER_VALIDATE_IP), 'author' => wp_stream_filter_input(INPUT_GET, 'author', FILTER_SANITIZE_NUMBER_INT), 'author_role' => wp_stream_filter_input(INPUT_GET, 'author_role'), 'date' => wp_stream_filter_input(INPUT_GET, 'date'), 'date_from' => wp_stream_filter_input(INPUT_GET, 'date_from'), 'date_to' => wp_stream_filter_input(INPUT_GET, 'date_to'), 'record__in' => wp_stream_filter_input(INPUT_GET, 'record__in'), 'order' => wp_stream_filter_input(INPUT_GET, 'order'), 'orderby' => wp_stream_filter_input(INPUT_GET, 'orderby'), 'fields' => wp_stream_filter_input(INPUT_GET, 'fields'));
     $records = wp_stream_query($args);
     $latest_record = isset($records[0]->created) ? $records[0]->created : null;
     $records_admin_url = add_query_arg(array('page' => WP_Stream_Admin::RECORDS_PAGE_SLUG), admin_url(WP_Stream_Admin::ADMIN_PARENT_PAGE));
     $latest_link = null;
     if (isset($records[0]->ID)) {
         $latest_link = add_query_arg(array('record__in' => $records[0]->ID), $records_admin_url);
     }
     $domain = parse_url($records_admin_url, PHP_URL_HOST);
     $format = wp_stream_filter_input(INPUT_GET, self::FEED_TYPE_QUERY_VAR);
     if ('atom' === $format) {
         require_once WP_STREAM_INC_DIR . 'feeds/atom.php';
     } elseif ('json' === $format) {
         require_once WP_STREAM_INC_DIR . 'feeds/json.php';
     } else {
         require_once WP_STREAM_INC_DIR . 'feeds/rss-2.0.php';
     }
     exit;
 }
Esempio n. 20
0
 function get_records($args = array())
 {
     $defaults = array('ignore_url_params' => false);
     $args = wp_parse_args($args, $defaults);
     // Parse sorting params
     if (!($order = wp_stream_filter_input(INPUT_GET, 'order'))) {
         $order = 'DESC';
     }
     if (!($orderby = wp_stream_filter_input(INPUT_GET, 'orderby'))) {
         $orderby = '';
     }
     $args['order'] = $order;
     $args['orderby'] = $orderby;
     $args['paged'] = $this->get_pagenum();
     $args['type'] = 'notification_rule';
     $args['blog_id'] = is_network_admin() ? 0 : get_current_blog_id();
     $args['ignore_context'] = true;
     if (!$args['ignore_url_params']) {
         $allowed_params = array('search', 'visibility', 'date');
         foreach ($allowed_params as $param) {
             if ($paramval = wp_stream_filter_input(INPUT_GET, $param)) {
                 $args[$param] = $paramval;
             }
         }
     }
     if (!isset($args['records_per_page'])) {
         $args['records_per_page'] = $this->get_items_per_page('edit_stream_notifications_per_page', 20);
     }
     $items = wp_stream_query($args);
     return $items;
 }