Generate pagination

@param  Content $content
@return void
515518
private function paginate(Content $content)
    {
        $maxPerPage = $this->app->getSetting('max_per_page', 15);
        $posts = $this->getPosts($content);

        $slices = [];
        $slice = [];
        $totalItems = 0;

        foreach ($posts as $k => $v)
        {
            if (count($slice) === $maxPerPage) {
                $slices[] = $slice;
                $slice = [];
            }

            $slice[$k] = $v;
            $totalItems++;
        }

        $slices[] = $slice;

        // Base URL
        $pageRoot = '/' . dirname($content->target);

        // Pagination data
        $pagination = [
            'total_posts' => count($posts),
            'total_pages' => count($slices),
            'next' => null,
            'prev' => null
        ];

        $pageNumber = 0;
        foreach ($slices as $slice)
        {
            $pageNumber++;

            // Set page target filename
            $target = ($pageNumber > 1) ? "{$pageRoot}/page/{$pageNumber}" : $content->target;

            // Previous page is index
            if ($pageNumber === 2) {
                $pagination['prev'] = $this->getUrl($pageRoot);
            }
            // Set previous page
            else if ($pageNumber > 1) {
                $pagination['prev'] = $this->getUrl("{$pageRoot}/page/" . ($pageNumber - 1));
            }
            // No previous page
            else {
                $pagination['prev'] = null;
            }

            // Set next page
            if ($pageNumber + 1 <= $pagination['total_pages']) {
                $pagination['next'] = $this->getUrl("{$pageRoot}/page/" . ($pageNumber + 1));
            }
            // No next page
            else {
                $pagination['next'] = null;
            }

            // Set current page
            $pagination['page'] = $pageNumber;

            // Set page URL
            $content->url = ($pageNumber > 1) ? $this->getUrl(dirname($target)) : $content->url;

            // Render content
            $html = $this->twig->render($content->id, [
                'page' => $content,
                'posts' => $slice,
                'pagination' => $pagination,
                'parent' => $this->getParent($content->parentId)
            ]);

            // Fire event
            Event::fire('paginate.before', [$this, &$target, &$html]);

            // Save Content
            $this->savePage($target, $html);
        }
    }
119212
public static function append($section, $content)
	{
		if (isset(static::$sections[$section]))
		{
			static::$sections[$section] .= $content;
		}
		else
		{
			static::$sections[$section] = $content;
		}
	}
1252662
public function publishDraft( Content $content )
    {
        $this->getRepository()->sudo(
            function(Repository $repository) use ( $content )
            {
                $repository->getContentService()->publishVersion($content->versionInfo->id);
            }
        );
    }
519785
protected function processUrlTag(string &$content): void
    {
        $pattern = $this->getTagPattern('url(\s+(.+?))?' . preg_quote($this->endTag, '/') . '(.+?)' . preg_quote($this->startTag . '/url', '/'));
        $content = preg_replace_callback($pattern, function ($match) {
            $matchName = $match[2];
            $matchPath = $match[3];
            $urlAsset = Application::$app->getService('urlAsset');
            if ($matchName == '') {
                return $urlAsset->getUrl($matchPath);
            } else {
                return $urlAsset->getUrl($matchPath, $matchName);
            }
        }, $content);
    }
582648
public static function createFromContent($content)
    {
        $domDocument = new \DOMDocument();

        @$domDocument->loadHTML($content);

        $xpathQueryBuilder = new XpathQueryBuilder();

        $xpathQueryBuilder->setDomXpath(new \DOMXPath($domDocument));

        return $xpathQueryBuilder;
    }
554012
public function edit($content)
    {
        $parent = BlockSelectOption::where('block_id', '=', $this->_block->id)->where('option', '=', 'parent')->first();
        $parentPageId = !empty($parent) ? $parent->value : 0;
        $this->_editViewData['selectOptions'] = [0 => '-- No Page Selected --'] + Page::get_page_list(['parent' => $parentPageId]);
        return parent::edit($content);
    }
928132
protected function getPages($content)
    {
        if ($content instanceof Pages) {
            return $content;
        }
        elseif ($content instanceof Site) {
            return $content->index();
        }
        else {
            $pages = new Pages([]);
            if ($content instanceof Page) $pages->add($content);
            return $pages;
        }
    }
803587
public function append( $content )
    {
        if (!is_array( $content )) {
            throw new RuntimeException( 'content for PDOWriter should be an array' );
        }

        try {
            $data   = $this->prepareValuesForInsert( $content );
            $writer = $this->prepareWriter( 1 );

            if (!$writer->execute( $data )) {
                throw new RuntimeException( 'Could not write PDO records' );
            }

            $this->incrementLineCount( $this->writer->rowCount() );
        } catch ( Exception $exception ) {
            if ($this->inTransaction) {
                $this->pdo->rollBack();
                $this->inTransaction = false;
            }

            throw $exception;
        }
    }
712508
public function indexContent(Content $content)
    {
        $fullTextValue = $this->mapper->mapContent($content);

        $this->indexerGateway->index($fullTextValue);
    }
221368
public function process(&$content)
    {
        //Add resources to the content
        $begin = "";
        $end = "";

        foreach ($this->tags as $tag) {
            if ($tag["at"]=="begin") {
                $begin.=$this->renderTag($tag);
            } else {
                $end.=$this->renderTag($tag);
            }
        }

        if ($begin!=='') {
            $count=0;
            $content=preg_replace(
                '/(<body\b[^>]*>)/is',
                '$1<###begin###>',
                $content,
                1,
                $count
            );
            if ($count) {
                $content=str_replace('<###begin###>', $begin, $content);
            } else {
                $content=$begin.$content;
            }
        }

        if ($end!=='') {
            $count=0;
            $content=preg_replace(
                '/(<\\/body\s*>)/is',
                '<###end###>$1',
                $content,
                1,
                $count
            );
            if ($count) {
                $content=str_replace('<###end###>', $end, $content);
            } else {
                $content=$content.$end;
            }
        }
    }
471278
public function includeThumb(Content $content)
    {
        $thumb = $content->thumb;
        return (!empty($thumb)) ? $this->item($thumb, new FileTransformer()) : null;
    }
502442
public function setDataContent($content)
    {
        if (is_array($content)) {
            $this->headers->set('Content-Type', 'application/json');
            $content = json_encode($content);
        }

        $this->setContent($content);
    }
250432
static function FirstChildOf (Content $content)
    {
        $provider = self::GetTreeProvider($content);
        if (!$provider)
        {
            return null;
        }
        $item = $provider->ItemByContent($content);
        return $provider->ContentByItem($provider->FirstChildOf($item));
    }
488822
public function renderNextLink($counter, $pageNumber, $content = '')
    {
        //create next link
        if ($pageNumber < $counter - 1) {
            $content .= "<a href='".$this->currentPageUrl.'/'.$this->next."'>next </a>";
        } else {
            $content .= '<span class="disabled">next </span>';
        }
        $content .= "</div>\n";

        return $content;
    }
224910
public function SetContent(Content $content)
    {
        $this->texts = array();
        $wordings = ContentWording::Schema()->FetchByContent(false, $content);
        foreach($wordings as $wording)
        {
            $prefix = Str::Replace('-', '.', $content->GetType());
            $this->texts[$prefix . '.' . $wording->GetPlaceholder()] = $wording->GetText();
        }
    }
511277
public function row($content)
    {
        if ($content instanceof Closure) {
            $row = new Row();
            call_user_func($content, $row);
            $this->addRow($row);
        } else {
            $this->addRow(new Row($content));
        }

        return $this;
    }
969678
public function write($content) {
        if (is_string($content) || is_numeric($content)) {
            $this->writeString($content);
        } elseif (is_bool($content)) {
            $this->writeString($content ? "TRUE" : "FALSE");
        } elseif (is_array($content)) {
            $this->writeString("Array(" . count($content) . ")");
        } elseif (is_object($content) && method_exists($content, "__toString")) {
            $this->writeString(strval($content));
        } elseif (is_null($content)) {
            $this->writeString("NULL");
        } elseif (is_resource($content)) {
            $this->writeString("Resource###");
        } else {
            throw new InvalidContentException();
        }
    }