Skip to content

Commit

Permalink
Merge pull request #1 from nliautaud/pico-2.0
Browse files Browse the repository at this point in the history
Pico 2.0 support
  • Loading branch information
nliautaud committed Jul 4, 2018
2 parents 47a2a7e + cb6bd40 commit fd32c4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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

0 comments on commit fd32c4e

Please sign in to comment.