Creates new collection with only published pages

@return Collection The collection with only published pages
188854
public function published()
    {
        $published = [];

        foreach ($this->items as $path => $slug) {
            $page = $this->pages->get($path);
            if ($page !== null && $page->published()) {
                $published[$path] = $slug;
            }
        }
        $this->items = $published;

        return $this;
    }
506600
public Set<PageRef> getPageLinks() {
		synchronized(lock) {
			if(pageLinks == null) return Collections.emptySet();
			if(frozen) return pageLinks;
			return AoCollections.unmodifiableCopySet(pageLinks);
		}
	}
282405
public I addPages(Collection<WebPage> webPages) {
        for (WebPage webPage : webPages) {
            addPage(webPage);
        }
        return getThis();
    }
931349
final public function findAll()
    {
        $this->query->setStartSelect();

        $this->query->prepare()->bindWhere()->bindLimit()->execute();

        $this->setRowCount();

        $collection = new Collection($this, $this->query->getSqlQuery());

        $this->query->close();

        return $collection();
    }
1225940
public function createCollection()
    {
        $collectClass = $this->collectionClass();
        if ($collectClass === 'array') {
            return [];
        }

        if (!class_exists($collectClass)) {
            throw new RuntimeException(sprintf(
                'Collection class [%s] does not exist.',
                $collectClass
            ));
        }

        if (!is_subclass_of($collectClass, ArrayAccess::class)) {
            throw new RuntimeException(sprintf(
                'Collection class [%s] must implement ArrayAccess.',
                $collectClass
            ));
        }

        $collection = new $collectClass;

        return $collection;
    }
410339
protected function getCollection()
    {
        $collection = [];

        $class = $this->getCollectionClassName();
        if ($class) {
            /** @var Collection $collection */
            $collection = new $class();
            $collection->setModel($this->class);
            $collection->setFormatter($this);
        }

        return $collection;
    }
1285985
public static function instances(): BaseCollection
    {
        $instances = new BaseCollection;

        foreach (static::make()->all() as $key => $value) {
            if ($instance = self::instance($key)) {
                $instances->put($key, $instance);
            }
        }

        return $instances;
    }
55344
public function createResultCollection($data = [], $method = 'create')
    {
        $collection = new ResultCollection();

        if (null === $data) {
            return $collection;
        }

        if (array_key_exists('page', $data)) {
            $collection->setPage($data['page']);
        }

        if (array_key_exists('total_pages', $data)) {
            $collection->setTotalPages($data['total_pages']);
        }

        if (array_key_exists('total_results', $data)) {
            $collection->setTotalResults($data['total_results']);
        }

        if (array_key_exists('results', $data)) {
            $data = $data['results'];
        }

        foreach ($data as $item) {
            $collection->add(null, $this->$method($item));
        }

        return $collection;
    }
367268
public function collection($params = 'content', $pagination = true)
    {
        if (is_string($params)) {
            $params = (array)$this->value('header.' . $params);
        } elseif (!is_array($params)) {
            throw new \InvalidArgumentException('Argument should be either header variable name or array of parameters');
        }

        if (!isset($params['items'])) {
            return new Collection();
        }

        // See if require published filter is set and use that, if assume published=true
        $only_published = true;
        if (isset($params['filter']['published']) && $params['filter']['published']) {
            $only_published = false;
        } elseif (isset($params['filter']['non-published']) && $params['filter']['non-published']) {
            $only_published = false;
        }

        $collection = $this->evaluate($params['items'], $only_published);
        if (!$collection instanceof Collection) {
            $collection = new Collection();
        }
        $collection->setParams($params);

        /** @var Uri $uri */
        $uri = Grav::instance()['uri'];
        /** @var Config $config */
        $config = Grav::instance()['config'];

        $process_taxonomy = $params['url_taxonomy_filters'] ?? $config->get('system.pages.url_taxonomy_filters');

        if ($process_taxonomy) {
            foreach ((array)$config->get('site.taxonomies') as $taxonomy) {
                if ($uri->param(rawurlencode($taxonomy))) {
                    $items = explode(',', $uri->param($taxonomy));
                    $collection->setParams(['taxonomies' => [$taxonomy => $items]]);

                    foreach ($collection as $page) {
                        // Don't filter modular pages
                        if ($page->modular()) {
                            continue;
                        }
                        foreach ($items as $item) {
                            $item = rawurldecode($item);
                            if (empty($page->taxonomy[$taxonomy]) || !\in_array(htmlspecialchars_decode($item, ENT_QUOTES), $page->taxonomy[$taxonomy], true)
                            ) {
                                $collection->remove($page->path());
                            }
                        }
                    }
                }
            }
        }

        // If  a filter or filters are set, filter the collection...
        if (isset($params['filter'])) {

            // remove any inclusive sets from filer:
            $sets = ['published', 'visible', 'modular', 'routable'];
            foreach ($sets as $type) {
                $var = "non-{$type}";
                if (isset($params['filter'][$type], $params['filter'][$var]) && $params['filter'][$type] && $params['filter'][$var]) {
                    unset ($params['filter'][$type], $params['filter'][$var]);
                }
            }

            foreach ((array)$params['filter'] as $type => $filter) {
                switch ($type) {
                    case 'published':
                        if ((bool) $filter) {
                            $collection->published();
                        }
                        break;
                    case 'non-published':
                        if ((bool) $filter) {
                            $collection->nonPublished();
                        }
                        break;
                    case 'visible':
                        if ((bool) $filter) {
                            $collection->visible();
                        }
                        break;
                    case 'non-visible':
                        if ((bool) $filter) {
                            $collection->nonVisible();
                        }
                        break;
                    case 'modular':
                        if ((bool) $filter) {
                            $collection->modular();
                        }
                        break;
                    case 'non-modular':
                        if ((bool) $filter) {
                            $collection->nonModular();
                        }
                        break;
                    case 'routable':
                        if ((bool) $filter) {
                            $collection->routable();
                        }
                        break;
                    case 'non-routable':
                        if ((bool) $filter) {
                            $collection->nonRoutable();
                        }
                        break;
                    case 'type':
                        $collection->ofType($filter);
                        break;
                    case 'types':
                        $collection->ofOneOfTheseTypes($filter);
                        break;
                    case 'access':
                        $collection->ofOneOfTheseAccessLevels($filter);
                        break;
                }
            }
        }

        if (isset($params['dateRange'])) {
            $start = $params['dateRange']['start'] ?? 0;
            $end = $params['dateRange']['end'] ?? false;
            $field = $params['dateRange']['field'] ?? false;
            $collection->dateRange($start, $end, $field);
        }

        if (isset($params['order'])) {
            $by = $params['order']['by'] ?? 'default';
            $dir = $params['order']['dir'] ?? 'asc';
            $custom = $params['order']['custom'] ?? null;
            $sort_flags = $params['order']['sort_flags'] ?? null;

            if (is_array($sort_flags)) {
                $sort_flags = array_map('constant', $sort_flags); //transform strings to constant value
                $sort_flags = array_reduce($sort_flags, function ($a, $b) {
                    return $a | $b;
                }, 0); //merge constant values using bit or
            }

            $collection->order($by, $dir, $custom, $sort_flags);
        }

        /** @var Grav $grav */
        $grav = Grav::instance();

        // New Custom event to handle things like pagination.
        $grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection]));

        // Slice and dice the collection if pagination is required
        if ($pagination) {
            $params = $collection->params();

            $limit = $params['limit'] ?? 0;
            $start = !empty($params['pagination']) ? ($uri->currentPage() - 1) * $limit : 0;

            if ($limit && $collection->count() > $limit) {
                $collection->slice($start, $limit);
            }
        }

        return $collection;
    }
822802
public function CreatePage()
	{
		$myWords = $this->WordCollection();

		$ht = array();
		$hasError = false;

		if ($this->_fromName == "")
		{
			$ht[$myWords->Value("FLDNAME")] = $myWords->Value("ERRORBLANK");
			$hasError = true;
		}
		if ($this->_fromEmail == "")
		{
			$ht[$myWords->Value("FLDEMAIL")] = $myWords->Value("ERRORBLANK");
			$hasError = true;
		}
		else
		{
			if (strrpos( $this->_fromEmail, "@") === false )
			{
				$ht[$myWords->Value("FLDEMAIL")] = $myWords->Value("FLDEMAIL") . " " . $myWords->Value("ERRORINVALID");
				$hasError = true;
			}
		}
		if ($this->_subject == "")
		{
			$ht[$myWords->Value("FLDSUBJECT")] = $myWords->Value("ERRORBLANK");
			$hasError = true;
		}
		if ($this->_message == "")
		{
			$ht[$myWords->Value("FLDMESSAGE")] = $myWords->Value("ERRORBLANK");
			$hasError = true;
		}

		if  ($hasError)
		{
			return $this->CreatePageArgs($myWords->Value("MSGERROR"), $ht);
		}
		elseif (!XmlInputImageValidate::validateText($this->_context))
		{
			$document = new XmlnukeDocument($myWords->ValueArgs("TITLE", array( $this->_context->get("SERVER_NAME")) ), $myWords->ValueArgs("ABSTRACT", array( $this->_context->get("SERVER_NAME")) ));
			$blockcenter = new XmlBlockCollection($myWords->Value("MSGERROR"), BlockPosition::Center );
			$document->addXmlnukeObject($blockcenter);

			$form = new XmlFormCollection($this->_context, "module:sendemail", $myWords->Value("MSGERROR"));
			$form->addXmlnukeObject(new XmlInputCaption($myWords->Value("RETRYVALIDATE")));
			$form->addXmlnukeObject(new XmlInputHidden("toname_id", $this->_context->get("toname_id")));
			$form->addXmlnukeObject(new XmlInputHidden("name", $this->_context->get("name")));
			$form->addXmlnukeObject(new XmlInputHidden("email", $this->_context->get("email")));
			$form->addXmlnukeObject(new XmlInputHidden("subject", $this->_context->get("subject")));
			$form->addXmlnukeObject(new XmlInputHidden("message", $this->_extraMessage . $this->_context->get("message")));
			$form->addXmlnukeObject(new XmlInputHidden("redirect", $this->_context->get("redirect")));
			$form->addXmlnukeObject(new XmlInputImageValidate(""));
			$buttons = new XmlInputButtons();
			$buttons->addSubmit($myWords->Value("RETRY"), "");
			$form->addXmlnukeObject($buttons);
			$blockcenter->addXmlnukeObject($form);

			return $document->generatePage();
		}
		else
		{
			$envelope = new MailEnvelope(MailUtil::getEmailFromID($this->_toName_ID), $this->_subject, $this->_extraMessage . $this->_message);
			$envelope->setFrom(MailUtil::getEmailFromID("DEFAULT", $this->_fromName));
			$envelope->setReplyTo(\ByJG\Mail\Util::getFullEmail($this->_fromEmail, $this->_fromName));
			$envelope->setBCC($this->_fromEmail);
			$envelope->Send();

			if ($this->_redirect != "")
			{
				//Redirect Here!!
				//Response.End
				return $document->generatePage();
			}
			else
			{
				$ht[$myWords->Value("FLDNAME")] = $this->_fromName . " [" . $this->_fromEmail . "]" ;
				$ht[$myWords->Value("FLDSUBJECT")] = $this->_subject;
				$ht[$myWords->Value("FLDMESSAGE")] = $this->_message ;

				return $this->CreatePageArgs($myWords->Value("MSGOK"), $ht);
			}
		}
	}
861401
public static IBundleProvider newEmptyList() {
		final InstantDt published = InstantDt.withCurrentTime();
		return new IBundleProvider() {
			@Override
			public List<IBaseResource> getResources(int theFromIndex, int theToIndex) {
				return Collections.emptyList();
			}

			@Override
			public Integer size() {
				return 0;
			}

			@Override
			public InstantDt getPublished() {
				return published;
			}

			@Override
			public Integer preferredPageSize() {
				return null;
			}

			@Override
			public String getUuid() {
				return null;
			}
		};
	}
271144
public function CreatePage()
	{
		$this->_myWords = $this->WordCollection();

		$this->_document = new XmlnukeDocument($this->_myWords->Value("TITLE", $this->_context->get("SERVER_NAME")),$this->_myWords->Value("ABSTRACT", $this->_context->get("SERVER_NAME")));

		if ($this->_link == "")
		{
			$this->goBack( $this->_myWords->Value("ERRORINVALID") );
		}
		elseif ($this->_action == "submit")
		{
			if (!XmlInputImageValidate::validateText($this->_context))
			{
					$this->goBack( $this->_myWords->Value("OBJECTIMAGEINVALID") );
			}
			else 
			{
				if ( ($this->_toName == "") || ($this->_toEmail == "") || ($this->_fromName == "") || ($this->_fromEmail == "") )
				{
					$this->goBack( $this->_myWords->Value("ERROR") );
				}
				else
				{
					$custMessage = $this->_myWords->Value("MESSAGE", array($this->_toName, $this->_toEmail, urldecode($this->_link), $this->_fromName, $this->_customMessage) );

					MailUtil::Mail
					(
						MailUtil::getEmailFromID(),
						MailUtil::getFullEmailName($this->_toName, $this->_toEmail),
						$this->_myWords->Value("SUBJECT"),
						"",
						$this->_fromEmail,$custMessage
					);

					$this->showMessage();
				}
			}
		}
		else
		{
			$this->showForm();
		}

		return $this->_document->generatePage();		
	}
590353
protected function createDefaultSet()
    {
        $pages = SiteTree::get();
        foreach ($pages as $page) {
            // Only handle valid page types
            if (!$page->config()->get('documents_enabled')) {
                $this->addResult('Skipped: documents disabled');
                continue;
            }

            if ($page->DocumentSets()->count()) {
                // Don't add a set if it already has one
                $this->addResult('Skipped: already has a set');
                continue;
            }
            $this->addDefaultDocumentSet($page);
            $this->addResult('Default document set added');
        }
        return $this;
    }
559980
public function presentChildren()
	{

		$childrenPages = new \WP_Query(
			array(
				'post_type'      => 'page',
				'post_parent'    => $this->ID,
				'post_status'    => 'publish',
				'orderby'        => 'menu_order',
				'order'          => 'ASC',
				'posts_per_page' => -1
			)
		);

		if (count($childrenPages->posts) == 0 || ! $childrenPages)
		{
			return null;
		}

		$pages = array();

		foreach ($childrenPages->posts as $p)
		{
			$pages[] = new self($p, false);
		}

		return Collection::make($pages);

	}
134337
@Override
  public Iterator<Page<T>> iterator() {

    return new Iterator<Page<T>>() {

      int currentIndex = 0;
      int currentPageNumber = 1;
      int pageSize = getPageSize();

      @Override
      public boolean hasNext() {
        return this.currentIndex < getList().size();
      }

      @Override
      public Page<T> next() {

        Assert.isTrue(hasNext(), new NoSuchElementException("No more pages"));

        Page<T> page = SimplePage.of(SimplePageable.this, this.currentPageNumber);

        this.currentIndex += this.pageSize;
        this.currentPageNumber++;

        return page;
      }
    };
  }
106574
public function CreatePage() 
	{
		parent::CreatePage();
		
		$this->myWords = $this->WordCollection();
		$this->setTitlePage($this->myWords->Value("TITLE"));
		$this->setHelp($this->myWords->Value("DESCRIPTION"));

		$block = new XmlBlockCollection($this->myWords->Value("TITLE"), BlockPosition::Center);
		
		$this->addMenuItem($this->_moduleUrl, $this->myWords->Value("MENULISTPOLLS"), "");
		$this->addMenuItem("module:Xmlnuke.Admin.ManageDBConn", $this->myWords->Value("MENUMANAGEDBCONN"), "");
			
		// Create a NEW config file and SETUP Database
		$configfile = new AnydatasetFilenameProcessor("_poll");
		if (!FileUtil::Exists($configfile))
		{
			$this->CreateSetup($block);
		}
		else 
		{
			$anyconfig = new AnyDataset($configfile->FullQualifiedNameAndPath());
			$it = $anyconfig->getIterator();
			if ($it->hasNext())
			{
				$sr = $it->moveNext();
				$this->_isdb = $sr->getField("dbname") != "-anydata-";
				$this->_connection = $sr->getField("dbname");
				$this->_tblanswer = $sr->getField("tbl_answer");
				$this->_tblpoll = $sr->getField("tbl_poll");
				$this->_tbllastip = $sr->getField("tbl_lastip");
			}
			else 
			{
				$this->CreateSetup($block);
				$this->defaultXmlnukeDocument->addXmlnukeObject($block);
				return $this->defaultXmlnukeDocument->generatePage();
			}
			
			if ($this->_context->get("op") == "")
			{
				$this->ListPoll($block);
			}
			elseif ($this->_context->get("op") == "answer")
			{
				$polldata = explode("|", $this->_context->get("valueid"));
				$this->ListAnswers($block, $polldata[0], $polldata[1]);
			}
			elseif ($this->_context->get("op") == "answernav")
			{
				$this->ListAnswers($block, $this->_context->get("curpoll"), $this->_context->get("curlang"));
			}
		}

		$this->defaultXmlnukeDocument->addXmlnukeObject($block);
		return $this->defaultXmlnukeDocument->generatePage();
	}
825666
public function getFilteredPages()
    {
        $pages = Versioned::get_by_stage(SiteTree::class, 'Stage');
        $pages = $this->applyDefaultFilters($pages);
        $pages = $pages->filterByCallback(function (SiteTree $page) {
            // If page exists on stage but not on live
            return $page->isOnDraftOnly();
        });
        return $pages;
    }