Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pico 2.0 support #1

Merged
merged 3 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions PicoOutput.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php
/**
* Output the page content or data as raw, html, json or xml with `?output`.
* Output Pico CMS page data as raw text, html, json or xml with `?output`.
*
* @author Nicolas Liautaud
* @link https://github.com/nliautaud/pico-content-output
* @link http://picocms.org
* @license http://opensource.org/licenses/MIT The MIT License
* @version 0.1.0
*/
final class PicoOutput extends AbstractPicoPlugin
{
const API_VERSION = 2;

private $serveContent;
private $contentFormat;

Expand Down Expand Up @@ -59,23 +60,27 @@ public function enabledFormat()
private function contentOutput()
{
$pico = $this->getPico();
$page = $pico->getCurrentPage();
unset($page['previous_page']);
unset($page['next_page']);
unset($page['tree_node']);
switch ($this->contentFormat) {
case 'raw':
return $pico->getRawContent();
case 'prepared':
return $pico->prepareFileContent($pico->getRawContent(), $pico->getFileMeta());
case 'json':
header('Content-Type: application/json;charset=utf-8');
return json_encode($pico->getCurrentPage());
return json_encode($page);
case 'xml':
header("Content-type: text/xml");
$xml = new SimpleXMLElement('<page/>');
$this->array_to_xml($pico->getCurrentPage(), $xml);
$this->array_to_xml($page, $xml);
return $xml->asXML();
default:
return $pico->getFileContent();
}
}
}

// function defination to convert array to xml
private function array_to_xml( $data, &$xml_data )
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Pico Output

Output the page content or data as raw, html, json or xml with `?output` in [Pico CMS](http://picocms.org).
Output [Pico CMS](http://picocms.org) page data as raw text, html, json or xml with `?output`.

## Installation

Copy `PicoOutput.php` to the `plugins/` directory of your Pico Project.

## Usage

Enable the plugin and the output formats in Pico `config.php`.
Enable output formats in Pico config file.

```php
$config['PicoOutput.enabled'] = true; // by default
$config['PicoOutput.enabledFormats'] = array('content', 'prepared');
```yml
PicoOutput.enabled: true # by default
PicoOutput.enabledFormats: [content, raw, prepared, xml, json]
```

Then add `?output=format` to any url.
Expand Down