Skip to content

Commit

Permalink
Fix Documenter on PHP 7
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoboHub authored and nitriques committed Mar 21, 2017
1 parent ba2e94d commit ad1c11f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
17 changes: 12 additions & 5 deletions content/content.edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

class contentExtensionDocumenterEdit extends AdministrationPage {

function view() {
DocumentationForm::render();
private $form;

public function __construct() {
parent::__construct();
$this->form = new DocumentationForm($this);
}

public function view() {
$this->form->render();
}

function action() {
public function action() {
$doc_id = $this->_context[0];

// Delete action
Expand All @@ -31,10 +38,10 @@ function action() {
$fields['pages'] = implode(',',$fields['pages']);
}

$fields['content_formatted'] = DocumentationForm::applyFormatting($fields['content'], true, $this->_errors);
$fields['content_formatted'] = $this->form->applyFormatting($fields['content'], true, $this->_errors);

if($fields['content_formatted'] === false){
$fields['content_formatted'] = General::sanitize(DocumentationForm::applyFormatting($fields['content']));
$fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content']));
}

if(!isset($fields['content']) || trim($fields['content']) == '') $this->_errors['content'] = __('Content is a required field');
Expand Down
21 changes: 14 additions & 7 deletions content/content.new.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

class contentExtensionDocumenterNew extends AdministrationPage {

function view() {
DocumentationForm::render();
private $form;

public function __construct() {
parent::__construct();
$this->form = new DocumentationForm($this);
}

public function view() {
$this->form->render();
}
function action() {

public function action() {
if(@array_key_exists('save', $_POST['action'])){

$this->_errors = array();
Expand All @@ -21,10 +28,10 @@ function action() {
$fields['pages'] = implode(',',$fields['pages']);
}

$fields['content_formatted'] = DocumentationForm::applyFormatting($fields['content'], true, $this->_errors);
$fields['content_formatted'] = $this->form->applyFormatting($fields['content'], true, $this->_errors);

if($fields['content_formatted'] === false){
$fields['content_formatted'] = General::sanitize(DocumentationForm::applyFormatting($fields['content']));
$fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content']));
}

if(!isset($fields['title']) || trim($fields['title']) == '') $this->_errors['title'] = __('Title is a required field');
Expand All @@ -44,7 +51,7 @@ function action() {
}
}

if(is_array($this->_errors) && !empty($this->_errors)) $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
if(is_array($this->_errors) && !empty($this->_errors)) $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
}

}
52 changes: 29 additions & 23 deletions lib/class.form.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php

class DocumentationForm {

private $page;

public function __construct($page) {
$this->page = $page;
}

function render() {
public function render() {

$this->setPageType('form');
$this->page->setPageType('form');
$fields = array();

// If we're editing, make sure the item exists
if ($this->_context[0]) {
if (!$doc_id = $this->_context[0]) redirect(URL . '/symphony/extension/documenter/manage');
if ($this->page->_context[0]) {
if (!$doc_id = $this->page->_context[0]) redirect(URL . '/symphony/extension/documenter/manage');

$existing = Symphony::Database()->fetchRow(0, "
SELECT
Expand All @@ -22,7 +28,7 @@ function render() {
");

if (!$existing) {
$this->_Parent->customError(
$this->page->_Parent->customError(
E_USER_ERROR, __('Documentation Item not found'),
__('The documentation item you requested to edit does not exist.'),
false, true, 'error', array(
Expand All @@ -33,9 +39,9 @@ function render() {
}

// Build the status message
if (isset($this->_context[1])) {
if ($this->_context[1] == 'saved') {
$this->pageAlert(
if (isset($this->page->_context[1])) {
if ($this->page->_context[1] == 'saved') {
$this->page->pageAlert(
__('Documentation Item updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>',
array(Widget::Time()->generate(__SYM_TIME_FORMAT__),
URL . '/symphony/extension/documenter/new/',
Expand All @@ -44,7 +50,7 @@ function render() {
Alert::SUCCESS
);
} else {
$this->pageAlert(
$this->page->pageAlert(
__('Documentation Item created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>',
array(Widget::Time()->generate(__SYM_TIME_FORMAT__),
URL . '/symphony/extension/documenter/new/',
Expand All @@ -60,7 +66,7 @@ function render() {
if (isset($_POST['fields'])) {
$fields = $_POST['fields'];

} else if ($this->_context[0]) {
} else if ($this->page->_context[0]) {
$fields = $existing;
$fields['content'] = General::sanitize($fields['content']);
}
Expand All @@ -69,18 +75,18 @@ function render() {
if (trim($title) == '') $title = $existing['title'];

// Start building the page
$this->setTitle(__(
$this->page->setTitle(__(
($title ? '%1$s &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %2$s'),
array(
__('Symphony'),
__('Documentation'),
$title
)
));
$this->appendSubheading(($title ? $title : __('Untitled')));
$this->page->appendSubheading(($title ? $title : __('Untitled')));

// Start building the fieldsets
$this->Form->setAttribute('class', 'two columns');
$this->page->Form->setAttribute('class', 'two columns');

$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'primary column');
Expand All @@ -91,8 +97,8 @@ function render() {
'fields[title]', General::sanitize($fields['title'])
));

if (isset($this->_errors['title'])) {
$label = Widget::Error($label, $this->_errors['title']);
if (isset($this->page->_errors['title'])) {
$label = Widget::Error($label, $this->page->_errors['title']);
}
$fieldset->appendChild($label);

Expand All @@ -103,14 +109,14 @@ function render() {
if(Symphony::Configuration()->get('text-formatter', 'documentation') != 'none') $content->setAttribute('class', Symphony::Configuration()->get('text-formatter', 'documentation'));

$label->appendChild($content);
$fieldset->appendChild((isset($this->_errors['content']) ? Widget::Error($label, $this->_errors['content']) : $label));
$fieldset->appendChild((isset($this->page->_errors['content']) ? Widget::Error($label, $this->page->_errors['content']) : $label));

$fieldset->appendChild(Widget::Input('autogenerate',
__('Auto-generate content according to selected section(s)'),
'button', array('class'=>'button')
));

$this->Form->appendChild($fieldset);
$this->page->Form->appendChild($fieldset);

// Pages multi-select
$fieldset = new XMLElement('fieldset');
Expand Down Expand Up @@ -161,29 +167,29 @@ function render() {

$label->appendChild(Widget::Select('fields[pages][]', $options, array('multiple' => 'multiple', 'id' => 'documenter-pagelist')));

if (isset($this->_errors['pages'])) {
$label = Widget::Error($label, $this->_errors['pages']);
if (isset($this->page->_errors['pages'])) {
$label = Widget::Error($label, $this->page->_errors['pages']);
}

$fieldset->appendChild($label);
$this->Form->appendChild($fieldset);
$this->page->Form->appendChild($fieldset);

// Form actions

$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$div->appendChild(Widget::Input(
'action[save]', ($this->_context[0] ? __('Save Changes') : __('Document It')),
'action[save]', ($this->page->_context[0] ? __('Save Changes') : __('Document It')),
'submit', array('accesskey' => 's')
));

if($this->_context[0]){
if($this->page->_context[0]){
$button = new XMLElement('button', __('Delete'));
$button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this template')));
$div->appendChild($button);
}

$this->Form->appendChild($div);
$this->page->Form->appendChild($div);
}

function applyFormatting($data, $validate=false, &$errors=NULL){
Expand Down

0 comments on commit ad1c11f

Please sign in to comment.