All posts.

@since 160524 Post query utils.

@param array $args Behavioral args.

@return \WP_Post[] Array of posts.
540070
public function all(array $args = []): array
    {
        $WpDb = $this->s::wpDb();

        // Establish args.

        $default_args = [
            // Unique.
            'max'         => PHP_INT_MAX,
            'fail_on_max' => false,

            // Also used by {@link total()}.
            'for_comments_only' => false,

            'include_post_ids' => [],
            'exclude_post_ids' => [],

            'include_post_types' => [],
            'exclude_post_types' => [],

            'include_post_statuses' => [],
            'exclude_post_statuses' => [],

            'exclude_drafts'             => true,
            'exclude_revisions'          => true,
            'exclude_trash'              => true,
            'exclude_password_protected' => false,
            'exclude_nav_menu_items'     => true,

            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Also used by {@link total()}.
        $args['for_comments_only'] = (bool) $args['for_comments_only'];

        $args['include_post_ids'] = (array) $args['include_post_ids'];
        $args['exclude_post_ids'] = (array) $args['exclude_post_ids'];

        $args['include_post_types'] = (array) $args['include_post_types'];
        $args['exclude_post_types'] = (array) $args['exclude_post_types'];

        $args['include_post_statuses'] = (array) $args['include_post_statuses'];
        $args['exclude_post_statuses'] = (array) $args['exclude_post_statuses'];

        $args['exclude_drafts']             = (bool) $args['exclude_drafts'];
        $args['exclude_revisions']          = (bool) $args['exclude_revisions'];
        $args['exclude_trash']              = (bool) $args['exclude_trash'];
        $args['exclude_password_protected'] = (bool) $args['exclude_password_protected'];
        $args['exclude_nav_menu_items']     = (bool) $args['exclude_nav_menu_items'];

        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($posts = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $posts; // Already cached this.
        }
        // Automatically fail if there are too many; when/if desirable.

        if ($args['fail_on_max'] && $this->total($args) > $args['max']) {
            return $posts = []; // Fail; too many.
        }
        $sql = 'SELECT * FROM `'.esc_sql($WpDb->posts).'`'.

                ' WHERE 1=1'.// Initialize the WHERE clause in this query.

                ($args['include_post_ids'] ? ' AND `ID` IN('.$this->c::quoteSqlIn($args['include_post_ids']).')' : '').
                ($args['exclude_post_ids'] ? ' AND `ID` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_ids']).')' : '').

                ($args['include_post_types'] ? ' AND `post_type` IN('.$this->c::quoteSqlIn($args['include_post_types']).')' : '').
                ($args['exclude_post_types'] ? ' AND `post_type` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_types']).')' : '').

                ($args['include_post_statuses'] ? ' AND `post_status` IN('.$this->c::quoteSqlIn($args['include_post_statuses']).')' : '').
                ($args['exclude_post_statuses'] ? ' AND `post_status` NOT IN('.$this->c::quoteSqlIn($args['exclude_post_statuses']).')' : '').

                ($args['exclude_drafts'] ? " AND `post_type` NOT IN('draft','auto-draft')" : '').
                ($args['exclude_revisions'] ? " AND `post_type` != 'revision'" : '').
                ($args['exclude_trash'] ? " AND `post_status` != 'trash'" : '').
                ($args['exclude_password_protected'] ? " AND `post_password` = ''" : '').
                ($args['exclude_nav_menu_items'] ? " AND `post_type` != 'nav_menu_item'" : '').

                ($args['for_comments_only'] ? " AND (`comment_status` IN('1', 'open', 'opened') OR `comment_count` > '0')" : '').

                ' ORDER BY `post_type` ASC, `post_date_gmt` DESC'.($args['max'] !== PHP_INT_MAX ? ' LIMIT '.(int) $args['max'] : '');

        if (!($results = $WpDb->get_results($sql, OBJECT_K))) {
            return $posts = []; // No posts.
        }
        // Else we have results. Order & return array.

        $results_of_type = [ // Order of priority.
            'page'          => [],
            'post'          => [],
            'product'       => [],
            'topic'         => [],
            'reply'         => [],
            'attachment'    => [],
            'nav_menu_item' => [],
            '_other'        => [],
        ];
        // Break them down by type now.

        foreach ($results as $_key => $_result) {
            if (isset($results_of_type[$_result->post_type])) {
                $results_of_type[$_result->post_type][$_key] = $_result;
            } else {
                $results_of_type['_other'][$_key] = $_result;
            }
        } // unset($_key, $_result); // Housekeeping.

        $results = []; // In order of priority.
        foreach ($results_of_type as $_result_type => $_results) {
            $results += $_results; // Union of current + this type.
        } // unset($_result_type, $_results); // Housekeeping.

        $posts = []; // `WP_Post` instances.
        foreach ($results as $_key => $_post) {
            $posts[$_key] = new \WP_Post($_post);
        } // unset($_key, $_post); // Housekeeping.

        return $posts;
    }
751033
public function all(array $args = []): array
    {
        // Establish args.

        $default_args = [
            // Unique.
            'max'         => PHP_INT_MAX,
            'fail_on_max' => false,

            // Also used by {@link total()}.
            'include'                   => [],
            'exclude'                   => [],
            'exclude_deprecated_levels' => true,
            'no_cache'                  => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Also used by {@link total()}.
        $args['include']                   = (array) $args['include'];
        $args['exclude']                   = (array) $args['exclude'];
        $args['exclude_deprecated_levels'] = (bool) $args['exclude_deprecated_levels'];
        $args['no_cache']                  = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($caps = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $caps; // Already cached this.
        }
        // Automatically fail if there are too many; when/if desirable.

        if ($args['fail_on_max'] && $this->total($args) > $args['max']) {
            return $caps = []; // Fail; too many.
        }
        // Return the array of all caps now.

        $caps = $this->collectAll(); // All possible caps.

        $caps = $args['include'] ? array_intersect_key($caps, array_fill_keys($args['include'], true)) : $caps;
        $caps = $args['exclude'] ? array_diff_key($caps, array_fill_keys($args['exclude'], true)) : $caps;
        $caps = $args['exclude_deprecated_levels'] ? array_diff_key($caps, array_fill_keys($this->deprecated_levels, true)) : $caps;

        asort($caps, SORT_NATURAL); // Sort naturally.

        return $caps;
    }
317631
public static function make_request( array $args = [] ){
		$args = wp_parse_args([
			'blog' => get_option( 'home' ),
			'blog_lang' => get_locale(),
			'blog_charset' => get_option( 'blog_charset' ),
			'user_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
			'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
			'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
		], $args);
		// Add server variables
		foreach ( $_SERVER as $key => $value ) {
			switch( $key ){
				case 'REMOTE_ADDR':
				case 'HTTP_USER_AGENT':
				case 'HTTP_REFERER':
				case 'HTTP_COOKIE':
				case 'HTTP_COOKIE2':
				case 'PHP_AUTH_PW':
					// Ignore
					break;
				default:
					$args[$key] = $value;
					break;
			}
		}
		return http_build_query($args);
	}
63297
public function getPostsForArgs($args, $postClass = '\TimberPost', $collection = false)
    {
        return $this->getTimberBridge()->getPosts($args, $postClass, $collection);
    }
392964
public function setPost($data, ...$args)
    {
        if (is_array($data)) {
            return $this->set('post', $data);
        }

        if (count($args) === 0) {
            return $this;
        }

        return $this->set('post', $data, ...$args);
    }
362147
public function children( array $args = []) {
        $args = wp_parse_args( $args, [
            'parent'  => $this->ID,
            'fields'  => 'ids',
            'orderby' => 'comment_date_gmt',
            'order'   => 'ASC'
        ] );

        $query = new WP_Comment_Query;
        return $query->query( $args );
    }
449748
public function create(array $arguments)
    {
        $post = $this->mockAdapterPost($arguments);

        return wp_insert_post(array_merge(
            (array) $post->getAdaptee(),
            ['post_type' => $this->getSlug()]
        ));
    }
12355
protected function parseStatusArguments(string $status, array $args): array
    {
        $name = ucfirst($status);

        return wp_parse_args($args, [
            'label' => $name,
            'public' => true,
            'exclude_from_search' => false,
            'show_in_admin_all_list' => true,
            'show_in_admin_status_list' => true,
            'label_count' => _n_noop(
                $name.' <span class="count">(%s)</span>',
                $name.' <span class="count">(%s)</span>'
            ),
            'publish_text' => __('Apply Changes')
        ]);
    }
1059008
protected function getNewPosts()
    {
        Container::get('hooks')->fire('model.index.get_new_posts_start');

        $query['select'] = ['f.id', 'f.last_post'];
        $query['where'] = [
            ['fp.read_forum' => 'IS NULL'],
            ['fp.read_forum' => '1']
        ];
        $query = DB::forTable('forums')
            ->table_alias('f')
            ->select_many($query['select'])
            ->left_outer_join(
                DB::prefix().'forum_perms',
                '(`fp`.`forum_id`=`f`.`id` AND `fp`.`group_id`='.User::get()->g_id.')',
                'fp'
            )
//            ->left_outer_join(DB::prefix().'forum_perms', array('fp.forum_id', '=', 'f.id'), 'fp')
//            ->left_outer_join(DB::prefix().'forum_perms', array('fp.group_id', '=',
// User::get()->g_id), null, true)
//            ->where_any_is($query['where'])
            ->where_raw('(fp.read_forum IS NULL OR fp.read_forum = 1)')
            ->where_gt('f.last_post', User::get()->last_visit);

        $query = Container::get('hooks')->fireDB('model.index.query_get_new_posts', $query);

        $query = $query->find_result_set();

        $forums = $new_topics = [];
        $tracked_topics = Track::getTrackedTopics();

        foreach ($query as $cur_forum) {
            if (!isset($tracked_topics['forums'][$cur_forum->id]) ||
                $tracked_topics['forums'][$cur_forum->id] < $cur_forum->last_post) {
                $forums[$cur_forum->id] = $cur_forum->last_post;
            }
        }

        if (!empty($forums)) {
            if (empty($tracked_topics['topics'])) {
                $new_topics = $forums;
            } else {
                $query['select'] = ['forum_id', 'id', 'last_post'];

                $query = DB::forTable('topics')
                    ->select_many($query['select'])
                    ->where_in('forum_id', array_keys($forums))
                    ->where_gt('last_post', User::get()->last_visit)
                    ->where_null('moved_to');

                $query = Container::get('hooks')->fireDB('model.index.get_new_posts_query', $query);

                $query = $query->find_result_set();

                foreach ($query as $cur_topic) {
                    if (!isset($new_topics[$cur_topic->forum_id]) &&
                        (!isset($tracked_topics['forums'][$cur_topic->forum_id]) ||
                            $tracked_topics['forums'][$cur_topic->forum_id] < $forums[$cur_topic->forum_id]) &&
                        (!isset($tracked_topics['topics'][$cur_topic->id]) ||
                            $tracked_topics['topics'][$cur_topic->id] < $cur_topic->last_post)) {
                        $new_topics[$cur_topic->forum_id] = $forums[$cur_topic->forum_id];
                    }
                }
            }
        }

        $new_topics = Container::get('hooks')->fire('model.index.get_new_posts', $new_topics);

        return $new_topics;
    }
316916
public static function sortArgs(array &$args) {
        ksort($args);
        foreach ($args as $key => $val) {
            if (is_array($val)) {
                ksort($val);
                $args [ $key ] = $val;
                self::sortArgs($val);
            }
        }
    }
381936
public static function the_comments_pagination( $args = array() ) {
		?>
		<div class="c-pagination">
			<?php
			ob_start();

			$args = array_merge(
				$args,
				[
					'prev_text' => '<i class="fa fa-angle-left" aria-hidden="true"></i>',
					'next_text' => '<i class="fa fa-angle-right" aria-hidden="true"></i>',
				]
			);

			the_comments_pagination( $args );

			self::_sanitize_pagination_e( self::pagination( ob_get_clean() ) );
			?>
		</div>
		<?php
	}
216094
private function collection($args = null) {

        static $data = [];


        if(isset($args[1])) {
            
            if(preg_match('/(.*)\[(.*)\]/', $args[0], $matches)) {

                $data[$matches[1]][$matches[2]] = $args[1];

            } else {

                $data[$args[0]] = $args[1];

                return $args[1];
            }
        }

        return $data;
    }
1363218
protected function setArgs( $args ) {
		// Check for an API key being stored.
		if ( $this->getKey() ) {
			$args = wp_parse_args( $args, array( 'key' => $this->getKey() ) );
		}

		// Check for a site hash being stored.
		if ( $this->getSiteHash() ) {
			$args = wp_parse_args( $args, array( 'site_hash' => $this->getSiteHash() ) );
		}

		return $this->args = array(
			'timeout' => 15, // Default timeout is 5 seconds, change to 15.
			'body' => $args
		);
	}
1263252
public function normalize( array $args = [] )
	{
		$defaults = [
			'action'     => '',
			'attributes' => '',
			'id'         => '',
			'class'      => '',
			'enctype'    => 'multipart/form-data',
			'method'     => 'post',
			'nonce'      => '',
			'submit'     => __( 'Submit', 'site-reviews' ),
		];

		$this->args = array_merge( $defaults, $args );

		$attributes = $this->normalize->form( $this->args, 'implode' );

		$this->args['attributes'] = $attributes;

		return $this;
	}
16091
public function all(array $args = []): array
    {
        // Establish args.

        $default_args = [
            // Unique.
            'max'         => PHP_INT_MAX,
            'fail_on_max' => false,

            // Also used by {@link total()}.
            'filters' => [
                'orderby' => 'display_name',
            ],
            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        // Unique.
        $args['max']         = max(1, (int) $args['max']);
        $args['fail_on_max'] = (bool) $args['fail_on_max'];

        // Also used by {@link total()}.
        $args['filters']  = (array) $args['filters'];
        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($users = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $users; // Already cached this.
        }
        // Automatically fail if there are too many; when/if desirable.

        if ($args['fail_on_max'] && $this->total($args) > $args['max']) {
            return $users = []; // Fail; too many.
        }
        // Return the array of all user objects now.

        $WP_User_Query = new \WP_User_Query(array_merge($args['filters'], [
            'fields' => 'all_with_meta', 'offset' => 0, 'paged' => 1, 'number' => -1, 'count_total' => true,
        ]));
        return $users = $WP_User_Query->get_results();
    }
423239
public function total(array $args = []): int
    {
        // Establish args.

        $default_args = [
            // Also used by {@link all()}.
            'filters'  => [],
            'no_cache' => false,
        ];
        $args = array_merge($default_args, $args);
        $args = array_intersect_key($args, $default_args);

        $args['filters']  = (array) $args['filters'];
        $args['no_cache'] = (bool) $args['no_cache'];

        // Check cache; already did this query?

        $cache_keys = $args; // Keys to consider when checking the cache.
        unset($cache_keys['no_cache']); // Cache key exclusions.

        if (($total = &$this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
            return $total; // Already cached this.
        }
        // Establish total users in the query.

        $WP_User_Query = new \WP_User_Query(array_merge($args['filters'], [
            'fields' => 'ID', 'offset' => 0, 'paged' => 1, 'number' => 1, 'count_total' => true,
        ]));
        return $total = (int) $WP_User_Query->get_total();
    }
122600
private function parseArgs($args) {
        $command = $action = null;
        $params = [];
        foreach ($args as $argument) {
            if ('-' != $argument[0])
                if (null === $command)
                    $command = $argument;
                elseif (null === $action)
                    $action = $argument;
                else
                    $this->alert('Invalid argument ' . $argument . '!', ['command' => $command, 'action' => $action, 'serverArguments' => $_SERVER['argv'], 'processedArguments' => $args]);
            else {
                $argument = substr($argument, 1); // supports both  one - or two - ( - / -- )
                if ('-' == $argument[0])
                    $argument = substr($argument, 1);

                $argument = explode('=', $argument, 2);
                $params[$argument[0]] = isset($argument[1]) ? $argument[1] : true;
            }
        }
        return [
            'command' => $command,
            'action' => $action,
            'params' => $params
        ];
    }