forked from pointybeard-archives/xmlfield
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c9dee4
commit 190d657
Showing
5 changed files
with
191 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
# XML Field | ||
|
||
* Version: 1.1 | ||
* Author: Symphony Community (https://github.com/symphonists) | ||
* Build Date: 2011-03-22 | ||
* Requirements: Symphony 2.2 | ||
|
||
A textarea field that only accepts valid XML. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.field-xml textarea { | ||
font: 1.2rem/1.7 Monaco, Consolas, 'Andale Mono', monospace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
<?php | ||
|
||
class extension_XMLField extends Extension { | ||
|
||
public function uninstall() { | ||
Symphony::Database()->query("DROP TABLE `tbl_fields_xml`"); | ||
} | ||
|
||
public function install() { | ||
return Symphony::Database()->query("CREATE TABLE IF NOT EXISTS `tbl_fields_xml` ( | ||
`id` int(11) unsigned NOT NULL auto_increment, | ||
`field_id` int(11) unsigned NOT NULL, | ||
`size` int(3) unsigned NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `field_id` (`field_id`) | ||
) TYPE=MyISAM;" | ||
); | ||
} | ||
|
||
} | ||
class extension_XMLField extends Extension | ||
{ | ||
|
||
public function getSubscribedDelegates() | ||
{ | ||
return array( | ||
array( | ||
'page' => '/backend/', | ||
'delegate' => 'InitaliseAdminPageHead', | ||
'callback' => 'initaliseAdminPageHead' | ||
) | ||
); | ||
} | ||
|
||
public function initaliseAdminPageHead($context) | ||
{ | ||
$callback = Symphony::Engine()->getPageCallback(); | ||
|
||
if($callback['driver'] == 'publish' && $callback['context']['page'] != 'index') { | ||
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/xmlfield/assets/publish.xmlfield.css'); | ||
} | ||
} | ||
|
||
public function install() | ||
{ | ||
return Symphony::Database()->query( | ||
"CREATE TABLE IF NOT EXISTS `tbl_fields_xml` ( | ||
`id` int(11) unsigned NOT NULL auto_increment, | ||
`field_id` int(11) unsigned NOT NULL, | ||
`size` int(3) unsigned NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `field_id` (`field_id`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" | ||
); | ||
} | ||
|
||
public function uninstall() | ||
{ | ||
Symphony::Database()->query("DROP TABLE `tbl_fields_xml`"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,142 @@ | ||
<?php | ||
|
||
if (!defined('__IN_SYMPHONY__')) die('<h2>Symphony Error</h2><p>You cannot directly access this file</p>'); | ||
|
||
require_once(TOOLKIT . '/fields/field.textarea.php'); | ||
|
||
class FieldXML extends fieldTextarea { | ||
|
||
public function __construct(){ | ||
parent::__construct(); | ||
$this->_name = 'XML'; | ||
$this->_required = true; | ||
|
||
// Set defaults | ||
$this->set('show_column', 'no'); | ||
$this->set('required', 'yes'); | ||
} | ||
|
||
function checkPostFieldData($data, &$message, $entry_id=NULL){ | ||
|
||
$message = NULL; | ||
|
||
if($this->get('required') == 'yes' && strlen($data) == 0){ | ||
$message = __("'%s' is a required field.", array($this->get('label'))); | ||
return self::__MISSING_FIELDS__; | ||
} | ||
|
||
if(empty($data)) self::__OK__; | ||
|
||
include_once(TOOLKIT . '/class.xsltprocess.php'); | ||
$xsltProc =& new XsltProcess; | ||
|
||
if(!General::validateXML($data, $errors, false, $xsltProc)){ | ||
|
||
$message = __('"%1$s" contains invalid XML. The following error was returned: <br/><code>%2$s</code>', array($this->get('label'), $errors[0]['message'])); | ||
return self::__INVALID_FIELDS__; | ||
} | ||
|
||
return self::__OK__; | ||
|
||
} | ||
|
||
public function processRawFieldData($data, &$status, &$message=null, $simulate = false, $entry_id = null) { | ||
$status = self::__OK__; | ||
return array( | ||
'value' => $data | ||
); | ||
} | ||
|
||
public function displaySettingsPanel(&$wrapper, $errors = null) { | ||
Field::displaySettingsPanel($wrapper, $errors); | ||
|
||
// Textarea Size | ||
$label = Widget::Label(__('Number of default rows')); | ||
$label->setAttribute('class', 'column'); | ||
$input = Widget::Input('fields['.$this->get('sortorder').'][size]', (string)$this->get('size')); | ||
$label->appendChild($input); | ||
|
||
$div = new XMLElement('div'); | ||
$div->setAttribute('class', 'two columns'); | ||
$div->appendChild($label); | ||
$wrapper->appendChild($div); | ||
|
||
$div = new XMLElement('div', NULL, array('class' => 'two columns')); | ||
$this->appendRequiredCheckbox($div); | ||
$this->appendShowColumnCheckbox($div); | ||
$wrapper->appendChild($div); | ||
} | ||
|
||
function createTable(){ | ||
return Symphony::Database()->query( | ||
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( | ||
`id` int(11) unsigned NOT NULL auto_increment, | ||
`entry_id` int(11) unsigned NOT NULL, | ||
`value` text, | ||
PRIMARY KEY (`id`), | ||
KEY `entry_id` (`entry_id`), | ||
FULLTEXT KEY `value` (`value`) | ||
) TYPE=MyISAM;" | ||
|
||
); | ||
} | ||
|
||
public function commit(){ | ||
if(!Field::commit()) return false; | ||
|
||
$id = $this->get('id'); | ||
|
||
if($id === false) return false; | ||
|
||
$fields = array(); | ||
$fields['size'] = $this->get('size'); | ||
|
||
return FieldManager::saveSettings($id, $fields); | ||
} | ||
|
||
public function fetchIncludableElements() { | ||
return array( | ||
$this->get('element_name') | ||
); | ||
} | ||
|
||
function appendFormattedElement(&$wrapper, $data, $encode=false){ | ||
$value = trim($data['value']); | ||
$wrapper->appendChild(new XMLElement($this->get('element_name'), ($encode ? General::sanitize($value) : $value))); | ||
} | ||
|
||
function checkFields(&$required, $checkForDuplicates=true, $checkForParentSection=true){ | ||
$required = array(); | ||
if($this->get('size') == '' || !is_numeric($this->get('size'))) $required[] = 'size'; | ||
return parent::checkFields($required, $checkForDuplicates, $checkForParentSection); | ||
} | ||
|
||
public function prepareTableValue($data, XMLElement $link = null) { | ||
$max_length = Symphony::Configuration()->get('cell_truncation_length', 'symphony'); | ||
$max_length = ($max_length ? $max_length : 75); | ||
|
||
$value = $data['value']; | ||
|
||
if(function_exists('mb_substr')) { | ||
$value = (strlen($value) <= $max_length ? $value : mb_substr($value, 0, $max_length, 'utf-8') . '...'); | ||
} | ||
else { | ||
$value = (strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '...'); | ||
} | ||
|
||
if (strlen($value) == 0) $value = __('None'); | ||
|
||
if ($link) { | ||
$link->setValue(htmlspecialchars($value)); | ||
return $link->generate(); | ||
} | ||
|
||
return htmlspecialchars($value); | ||
} | ||
|
||
} | ||
|
||
if (!defined('__IN_SYMPHONY__')) { | ||
die('<h2>Symphony Error</h2><p>You cannot directly access this file</p>'); | ||
} | ||
|
||
require_once(TOOLKIT . '/fields/field.textarea.php'); | ||
|
||
class FieldXML extends fieldTextarea | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->_name = 'XML'; | ||
$this->_required = true; | ||
|
||
// Set defaults | ||
$this->set('show_column', 'no'); | ||
$this->set('required', 'yes'); | ||
} | ||
|
||
public function checkPostFieldData($data, &$message, $entry_id = null) | ||
{ | ||
$message = null; | ||
|
||
if ($this->get('required') == 'yes' && strlen($data) == 0) { | ||
$message = __("'%s' is a required field.", array($this->get('label'))); | ||
|
||
return self::__MISSING_FIELDS__; | ||
} | ||
|
||
if (empty($data)) { | ||
self::__OK__; | ||
} | ||
|
||
include_once(TOOLKIT . '/class.xsltprocess.php'); | ||
$xsltProc =& new XsltProcess; | ||
|
||
if (!General::validateXML($data, $errors, false, $xsltProc)) { | ||
|
||
$message = __('"%1$s" contains invalid XML. The following error was returned: <br/><code>%2$s</code>', array($this->get('label'), $errors[0]['message'])); | ||
|
||
return self::__INVALID_FIELDS__; | ||
} | ||
|
||
return self::__OK__; | ||
|
||
} | ||
|
||
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) | ||
{ | ||
$status = self::__OK__; | ||
|
||
return array( | ||
'value' => $data | ||
); | ||
} | ||
|
||
public function displaySettingsPanel(&$wrapper, $errors = null) | ||
{ | ||
Field::displaySettingsPanel($wrapper, $errors); | ||
|
||
// Textarea Size | ||
$label = Widget::Label(__('Number of default rows')); | ||
$label->setAttribute('class', 'column'); | ||
$input = Widget::Input('fields['.$this->get('sortorder').'][size]', (string)$this->get('size')); | ||
$label->appendChild($input); | ||
|
||
$div = new XMLElement('div'); | ||
$div->setAttribute('class', 'two columns'); | ||
$div->appendChild($label); | ||
$wrapper->appendChild($div); | ||
|
||
$div = new XMLElement('div', NULL, array('class' => 'two columns')); | ||
$this->appendRequiredCheckbox($div); | ||
$this->appendShowColumnCheckbox($div); | ||
$wrapper->appendChild($div); | ||
} | ||
|
||
public function createTable() | ||
{ | ||
return Symphony::Database()->query( | ||
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( | ||
`id` int(11) unsigned NOT null auto_increment, | ||
`entry_id` int(11) unsigned NOT null, | ||
`value` text, | ||
PRIMARY KEY (`id`), | ||
KEY `entry_id` (`entry_id`), | ||
FULLTEXT KEY `value` (`value`) | ||
) TYPE=MyISAM;" | ||
); | ||
} | ||
|
||
public function fetchIncludableElements() | ||
{ | ||
return array( | ||
$this->get('element_name') | ||
); | ||
} | ||
|
||
public function appendFormattedElement(&$wrapper, $data, $encode = false) | ||
{ | ||
$value = trim($data['value']); | ||
$wrapper->appendChild(new XMLElement($this->get('element_name'), ($encode ? General::sanitize($value) : $value))); | ||
} | ||
|
||
public function checkFields(&$required, $checkForDuplicates = true, $checkForParentSection = true) | ||
{ | ||
$required = array(); | ||
if ($this->get('size') == '' || !is_numeric($this->get('size'))) { | ||
$required[] = 'size'; | ||
} | ||
|
||
return parent::checkFields($required, $checkForDuplicates, $checkForParentSection); | ||
} | ||
|
||
public function prepareTableValue($data, XMLElement $link = null) | ||
{ | ||
$max_length = Symphony::Configuration()->get('cell_truncation_length', 'symphony'); | ||
$max_length = ($max_length ? $max_length : 75); | ||
|
||
$value = $data['value']; | ||
|
||
if (function_exists('mb_substr')) { | ||
$value = (strlen($value) <= $max_length ? $value : mb_substr($value, 0, $max_length, 'utf-8') . '...'); | ||
} else { | ||
$value = (strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '...'); | ||
} | ||
|
||
if (strlen($value) == 0) { | ||
$value = __('None'); | ||
} | ||
|
||
if ($link) { | ||
$link->setValue(htmlspecialchars($value)); | ||
|
||
return $link->generate(); | ||
} | ||
|
||
return htmlspecialchars($value); | ||
} | ||
} |