本文整理汇总了PHP中General::validateXML方法的典型用法代码示例。如果您正苦于以下问题:PHP General::validateXML方法的具体用法?PHP General::validateXML怎么用?PHP General::validateXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类General
的用法示例。
在下文中一共展示了General::validateXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
public function transform($data)
{
if (!General::validateXML($data, $errors, false, new XsltProcess())) {
throw new TransformException('Data returned is invalid.', $errors);
}
return $data;
}
示例2: save
public function save(MessageStack $errors)
{
$xsl_errors = new MessageStack();
if (strlen(trim($this->parameters()->xml)) == 0) {
$errors->append('xml', __('This is a required field'));
} elseif (!General::validateXML($this->parameters()->xml, $xsl_errors)) {
if (XSLProc::hasErrors()) {
$errors->append('xml', sprintf('XSLT specified is invalid. The following error was returned: "%s near line %s"', $xsl_errors->current()->message, $xsl_errors->current()->line));
} else {
$errors->append('xml', 'XSLT specified is invalid.');
}
}
return parent::save($errors);
}
示例3: checkPostFieldData
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: <code>%2$s</code>', array($this->get('label'), $errors[0]['message']));
return self::__INVALID_FIELDS__;
}
return self::__OK__;
}
示例4: __applyFormatting
protected function __applyFormatting($data, $validate = false, &$errors = NULL)
{
if ($this->get('formatter')) {
$formatter = TextformatterManager::create($this->get('formatter'));
$result = $formatter->run($data);
}
if ($validate === true) {
include_once TOOLKIT . '/class.xsltprocess.php';
if (!General::validateXML($result, $errors, false, new XsltProcess())) {
$result = html_entity_decode($result, ENT_QUOTES, 'UTF-8');
$result = $this->__replaceAmpersands($result);
if (!General::validateXML($result, $errors, false, new XsltProcess())) {
return false;
}
}
}
return $result;
}
示例5: execute
public function execute(array &$param_pool = null)
{
include_once TOOLKIT . '/class.xsltprocess.php';
$result = new XMLElement($this->dsParamROOTELEMENT);
$this->dsParamSTATIC = stripslashes($this->dsParamSTATIC);
if (!General::validateXML($this->dsParamSTATIC, $errors, false, new XsltProcess())) {
$result->appendChild(new XMLElement('error', __('XML is invalid.')));
$element = new XMLElement('errors');
foreach ($errors as $e) {
if (strlen(trim($e['message'])) == 0) {
continue;
}
$element->appendChild(new XMLElement('item', General::sanitize($e['message'])));
}
$result->appendChild($element);
} else {
$result->setValue($this->dsParamSTATIC);
}
return $result;
}
示例6: __actionEdit
public function __actionEdit($new = false)
{
$fields = $_POST['fields'];
$fields['dependencies'] = array();
try {
$result = RecipientGroupManager::create($this->_context[1]);
$fields['dependencies'] = $result->_dependencies;
} catch (Exception $e) {
}
if (isset($_POST['action']['delete'])) {
if (RecipientgroupManager::delete($this->_context[1])) {
redirect(SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups');
} else {
$this->pageAlert(__('Could not delete, please check file permissions'), Alert::ERROR);
return true;
}
}
$post_fields = new XMLElement('post-fields');
General::array_to_xml($post_fields, $fields);
$this->_XML->appendChild($post_fields);
$errors = new XMLElement('errors');
if (!empty($fields['name']) && !empty($fields['name-xslt']) && General::validateXML($fields['name-xslt'], $error, false) == true) {
try {
if (RecipientGroupManager::save(str_replace('_', '-', $this->_context[1]), $fields)) {
redirect(SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/edit/' . Lang::createHandle($fields['name'], 225, '_') . '/saved');
return true;
}
} catch (Exception $e) {
$this->pageAlert(__('Could not save: ' . $e->getMessage()), Alert::ERROR);
}
}
if (empty($fields['name'])) {
$errors->appendChild(new XMLElement('name', __('This field can not be empty.')));
}
if (strlen(Lang::createHandle($fields['name'])) == 0) {
$errors->appendChild(new XMLElement('name', __('This field must at least contain a number or a letter')));
}
if (empty($fields['name-xslt'])) {
$errors->appendChild(new XMLElement('name-xslt', __('This field can not be empty.')));
}
if (!General::validateXML($fields['name-xslt'], $error, false)) {
$errors->appendChild(new XMLElement('name-xslt', __('XML is invalid')));
}
$this->_XML->appendChild($errors);
$this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
}
示例7: action
public function action()
{
$this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL;
if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) {
$fields = $_POST['fields'];
$this->_errors = array();
if (!isset($fields['name']) || trim($fields['name']) == '') {
$this->_errors['name'] = __('Name is a required field.');
}
if (!isset($fields['body']) || trim($fields['body']) == '') {
$this->_errors['body'] = __('Body is a required field.');
} elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) {
$this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message']));
}
$fields['name'] = Lang::createFilename($fields['name']);
if (General::right($fields['name'], 4) != '.xsl') {
$fields['name'] .= '.xsl';
}
$file = UTILITIES . '/' . $fields['name'];
##Duplicate
if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) {
$this->_errors['name'] = __('A Utility with that name already exists. Please choose another.');
} elseif ($this->_context[0] == 'new' && is_file($file)) {
$this->_errors['name'] = __('A Utility with that name already exists. Please choose another.');
}
if (empty($this->_errors)) {
if ($this->_context[0] == 'new') {
/**
* Just before the Utility has been created
*
* @delegate UtilityPreCreate
* @since Symphony 2.2
* @param string $context
* '/blueprints/utilities/'
* @param string $file
* The path to the Utility file
* @param string $contents
* The contents of the `$fields['body']`, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('UtilityPreCreate', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body']));
} else {
/**
* Just before the Utility has been updated
*
* @delegate UtilityPreEdit
* @since Symphony 2.2
* @param string $context
* '/blueprints/utilities/'
* @param string $file
* The path to the Utility file
* @param string $contents
* The contents of the `$fields['body']`, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('UtilityPreEdit', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body']));
}
##Write the file
if (!($write = General::writeFile($file, $fields['body'], Symphony::Configuration()->get('write_mode', 'file')))) {
$this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR);
} else {
## Remove any existing file if the filename has changed
if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) {
General::deleteFile(UTILITIES . '/' . $this->_existing_file);
}
if ($this->_context[0] == 'new') {
/**
* Just after the Utility has been written to disk
*
* @delegate UtilityPostCreate
* @since Symphony 2.2
* @param string $context
* '/blueprints/utilities/'
* @param string $file
* The path to the Utility file
*/
Symphony::ExtensionManager()->notifyMembers('UtilityPostCreate', '/blueprints/utilities/', array('file' => $file));
} else {
/**
* Just after a Utility has been edited and written to disk
*
* @delegate UtilityPostEdit
* @since Symphony 2.2
* @param string $context
* '/blueprints/utilities/'
* @param string $file
* The path to the Utility file
*/
Symphony::ExtensionManager()->notifyMembers('UtilityPostEdit', '/blueprints/utilities/', array('file' => $file));
}
redirect(SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
}
}
} elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) {
/**
* Prior to deleting the Utility
*
* @delegate UtilityPreDelete
* @since Symphony 2.2
* @param string $context
* '/blueprints/utilities/'
* @param string $file
//.........这里部分代码省略.........
示例8: execute
public function execute(array &$param_pool = null)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
$this->dsParamURL = $this->parseParamURL($this->dsParamURL);
if (isset($this->dsParamXPATH)) {
$this->dsParamXPATH = $this->__processParametersInString($this->dsParamXPATH, $this->_env);
}
$stylesheet = new XMLElement('xsl:stylesheet');
$stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'));
$output = new XMLElement('xsl:output');
$output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
$stylesheet->appendChild($output);
$template = new XMLElement('xsl:template');
$template->setAttribute('match', '/');
$instruction = new XMLElement('xsl:copy-of');
// Namespaces
if (isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS)) {
foreach ($this->dsParamFILTERS as $name => $uri) {
$instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri);
}
}
// XPath
$instruction->setAttribute('select', $this->dsParamXPATH);
$template->appendChild($instruction);
$stylesheet->appendChild($template);
$stylesheet->setIncludeHeader(true);
$xsl = $stylesheet->generate(true);
$cache_id = md5($this->dsParamURL . serialize($this->dsParamFILTERS) . $this->dsParamXPATH);
$cache = new Cacheable(Symphony::Database());
$cachedData = $cache->read($cache_id);
$writeToCache = false;
$valid = true;
$creation = DateTimeObj::get('c');
$timeout = isset($this->dsParamTIMEOUT) ? (int) max(1, $this->dsParamTIMEOUT) : 6;
// Execute if the cache doesn't exist, or if it is old.
if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
if (Mutex::acquire($cache_id, $timeout, TMP)) {
$ch = new Gateway();
$ch->init($this->dsParamURL);
$ch->setopt('TIMEOUT', $timeout);
$ch->setopt('HTTPHEADER', array('Accept: text/xml, */*'));
$data = $ch->exec();
$info = $ch->getInfoLast();
Mutex::release($cache_id, TMP);
$data = trim($data);
$writeToCache = true;
// Handle any response that is not a 200, or the content type does not include XML, plain or text
if ((int) $info['http_code'] !== 200 || !preg_match('/(xml|plain|text)/i', $info['content_type'])) {
$writeToCache = false;
$result->setAttribute('valid', 'false');
// 28 is CURLE_OPERATION_TIMEOUTED
if ($info['curl_error'] == 28) {
$result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout)));
} else {
$result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type'])));
}
return $result;
// Handle where there is `$data`
} elseif (strlen($data) > 0) {
// If the XML doesn't validate..
if (!General::validateXML($data, $errors, false, new XsltProcess())) {
$writeToCache = false;
}
// If the `$data` is invalid, return a result explaining why
if ($writeToCache === false) {
$element = new XMLElement('errors');
$result->setAttribute('valid', 'false');
$result->appendChild(new XMLElement('error', __('Data returned is invalid.')));
foreach ($errors as $e) {
if (strlen(trim($e['message'])) == 0) {
continue;
}
$element->appendChild(new XMLElement('item', General::sanitize($e['message'])));
}
$result->appendChild($element);
return $result;
}
// If `$data` is empty, set the `force_empty_result` to true.
} elseif (strlen($data) == 0) {
$this->_force_empty_result = true;
}
// Failed to acquire a lock
} else {
$result->appendChild(new XMLElement('error', __('The %s class failed to acquire a lock, check that %s exists and is writable.', array('<code>Mutex</code>', '<code>' . TMP . '</code>'))));
}
// The cache is good, use it!
} else {
$data = trim($cachedData['data']);
$creation = DateTimeObj::get('c', $cachedData['creation']);
}
// If `$writeToCache` is set to false, invalidate the old cache if it existed.
if (is_array($cachedData) && !empty($cachedData) && $writeToCache === false) {
$data = trim($cachedData['data']);
$valid = false;
$creation = DateTimeObj::get('c', $cachedData['creation']);
if (empty($data)) {
$this->_force_empty_result = true;
}
}
// If `force_empty_result` is false and `$result` is an instance of
//.........这里部分代码省略.........
示例9: __formAction
public function __formAction()
{
$fields = $_POST['fields'];
$this->_errors = array();
if (trim($fields['name']) == '') {
$this->_errors['name'] = __('This is a required field');
}
if ($fields['source'] == 'static_xml') {
if (trim($fields['static_xml']) == '') {
$this->_errors['static_xml'] = __('This is a required field');
} else {
$xml_errors = NULL;
include_once TOOLKIT . '/class.xsltprocess.php';
General::validateXML($fields['static_xml'], $xml_errors, false, new XsltProcess());
if (!empty($xml_errors)) {
$this->_errors['static_xml'] = __('XML is invalid');
}
}
} elseif ($fields['source'] == 'dynamic_xml') {
if (trim($fields['dynamic_xml']['url']) == '') {
$this->_errors['dynamic_xml']['url'] = __('This is a required field');
}
if (trim($fields['dynamic_xml']['xpath']) == '') {
$this->_errors['dynamic_xml']['xpath'] = __('This is a required field');
}
if (!is_numeric($fields['dynamic_xml']['cache'])) {
$this->_errors['dynamic_xml']['cache'] = __('Must be a valid number');
} elseif ($fields['dynamic_xml']['cache'] < 1) {
$this->_errors['dynamic_xml']['cache'] = __('Must be greater than zero');
}
} elseif (is_numeric($fields['source'])) {
if (strlen(trim($fields['max_records'])) == 0 || is_numeric($fields['max_records']) && $fields['max_records'] < 1) {
if (isset($fields['paginate_results'])) {
$this->_errors['max_records'] = __('A result limit must be set');
}
} else {
if (!self::__isValidPageString($fields['max_records'])) {
$this->_errors['max_records'] = __('Must be a valid number or parameter');
}
}
if (strlen(trim($fields['page_number'])) == 0 || is_numeric($fields['page_number']) && $fields['page_number'] < 1) {
if (isset($fields['paginate_results'])) {
$this->_errors['page_number'] = __('A page number must be set');
}
} else {
if (!self::__isValidPageString($fields['page_number'])) {
$this->_errors['page_number'] = __('Must be a valid number or parameter');
}
}
}
$classname = Lang::createHandle($fields['name'], NULL, '_', false, true, array('@^[^a-z\\d]+@i' => '', '/[^\\w-\\.]/i' => ''));
$rootelement = str_replace('_', '-', $classname);
##Check to make sure the classname is not empty after handlisation.
if (empty($classname)) {
$this->_errors['name'] = __('Please ensure name contains at least one Latin-based alphabet.', array($classname));
}
$file = DATASOURCES . '/data.' . $classname . '.php';
$isDuplicate = false;
$queueForDeletion = NULL;
if ($this->_context[0] == 'new' && is_file($file)) {
$isDuplicate = true;
} elseif ($this->_context[0] == 'edit') {
$existing_handle = $this->_context[1];
if ($classname != $existing_handle && is_file($file)) {
$isDuplicate = true;
} elseif ($classname != $existing_handle) {
$queueForDeletion = DATASOURCES . '/data.' . $existing_handle . '.php';
}
}
##Duplicate
if ($isDuplicate) {
$this->_errors['name'] = __('A Data source with the name <code>%s</code> name already exists', array($classname));
}
if (empty($this->_errors)) {
$dsShell = file_get_contents(TEMPLATE . '/datasource.tpl');
$params = array('rootelement' => $rootelement);
$about = array('name' => $fields['name'], 'version' => 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), 'release date' => DateTimeObj::getGMT('c'), 'author name' => Administration::instance()->Author->getFullName(), 'author website' => URL, 'author email' => Administration::instance()->Author->get('email'));
$source = $fields['source'];
$filter = NULL;
$elements = NULL;
switch ($source) {
case 'authors':
$filters = $fields['filter']['author'];
$elements = $fields['xml_elements'];
$params['order'] = $fields['order'];
$params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
$params['requiredparam'] = trim($fields['required_url_param']);
$params['paramoutput'] = $fields['param'];
$params['sort'] = $fields['sort'];
$dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.author.php');", $dsShell);
break;
case 'navigation':
$filters = $fields['filter']['navigation'];
$params['order'] = $fields['order'];
$params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
$params['requiredparam'] = trim($fields['required_url_param']);
$dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.navigation.php');", $dsShell);
break;
case 'dynamic_xml':
$namespaces = $fields['dynamic_xml']['namespace'];
//.........这里部分代码省略.........
示例10: Gateway
$writeToCache = false;
$valid = true;
$result = NULL;
$creation = DateTimeObj::get('c');
if (!$cachedData || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
if (Mutex::acquire($cache_id, 6, TMP)) {
$ch = new Gateway();
$ch->init();
$ch->setopt('URL', $this->dsParamURL);
$ch->setopt('TIMEOUT', 6);
$xml = $ch->exec();
$writeToCache = true;
Mutex::release($cache_id, TMP);
$xml = trim($xml);
if (!empty($xml)) {
$valid = General::validateXML($xml, $errors, false, $proc);
if (!$valid) {
if ($cachedData) {
$xml = $cachedData['data'];
} else {
$result = new XMLElement($this->dsParamROOTELEMENT);
$result->setAttribute('valid', 'false');
$result->appendChild(new XMLElement('error', __('XML returned is invalid.')));
}
}
} else {
$this->_force_empty_result = true;
}
} elseif ($cachedData) {
$xml = trim($cachedData['data']);
$valid = false;
示例11: action
function action()
{
$this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL;
if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) {
$fields = $_POST['fields'];
$this->_errors = array();
if (!isset($fields['name']) || trim($fields['name']) == '') {
$this->_errors['name'] = __('Name is a required field.');
}
if (!isset($fields['body']) || trim($fields['body']) == '') {
$this->_errors['body'] = __('Body is a required field.');
} elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) {
$this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message']));
}
if (empty($this->_errors)) {
$fields['name'] = Lang::createFilename($fields['name']);
if (General::right($fields['name'], 4) != '.xsl') {
$fields['name'] .= '.xsl';
}
$file = UTILITIES . '/' . $fields['name'];
##Duplicate
if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) {
$this->_errors['name'] = __('A Utility with that name already exists. Please choose another.');
} elseif ($this->_context[0] == 'new' && is_file($file)) {
$this->_errors['name'] = __('A Utility with that name already exists. Please choose another.');
} elseif (!($write = General::writeFile($file, $fields['body'], $this->_Parent->Configuration->get('write_mode', 'file')))) {
$this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR);
} else {
## Remove any existing file if the filename has changed
if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) {
General::deleteFile(UTILITIES . '/' . $this->_existing_file);
}
## TODO: Fix me
###
# Delegate: Edit
# Description: After saving the asset, the file path is provided.
//$ExtensionManager->notifyMembers('Edit', getCurrentPage(), array('file' => $file));
redirect(URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
}
}
} elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) {
## TODO: Fix me
###
# Delegate: Delete
# Description: Prior to deleting the asset file. Target file path is provided.
//$ExtensionManager->notifyMembers('Delete', getCurrentPage(), array('file' => WORKSPACE . '/' . $this->_existing_file_rel));
General::deleteFile(UTILITIES . '/' . $this->_existing_file);
redirect(URL . '/symphony/blueprints/components/');
}
}
示例12: stripslashes
<?php
include_once TOOLKIT . '/class.xsltprocess.php';
$this->dsSTATIC = stripslashes($this->dsSTATIC);
if (!General::validateXML($this->dsSTATIC, $errors, false, new XsltProcess())) {
$result->appendChild(new XMLElement('error', __('XML is invalid.')));
$element = new XMLElement('errors');
foreach ($errors as $e) {
if (strlen(trim($e['message'])) == 0) {
continue;
}
$element->appendChild(new XMLElement('item', General::sanitize($e['message'])));
}
$result->appendChild($element);
} else {
$result->setValue($this->dsSTATIC);
}
示例13: __actionEdit
function __actionEdit()
{
if (!($page_id = $this->_context[1])) {
redirect(URL . '/symphony/blueprints/pages/');
}
if (@array_key_exists('delete', $_POST['action'])) {
## TODO: Fix Me
###
# Delegate: Delete
# Description: Prior to deletion. Provided with Page's database ID
//$ExtensionManager->notifyMembers('Delete', getCurrentPage(), array('page' => $page_id));
$page = $this->_Parent->Database->fetchRow(0, "SELECT * FROM tbl_pages WHERE `id` = '{$page_id}'");
$filename = $page['path'] . '_' . $page['handle'];
$filename = trim(str_replace('/', '_', $filename), '_');
$this->_Parent->Database->delete('tbl_pages', " `id` = '{$page_id}'");
$this->_Parent->Database->delete('tbl_pages_types', " `page_id` = '{$page_id}'");
$this->_Parent->Database->query("UPDATE tbl_pages SET `sortorder` = (`sortorder` + 1) WHERE `sortorder` < '{$page_id}'");
General::deleteFile(PAGES . "/{$filename}.xsl");
redirect(URL . '/symphony/blueprints/pages/');
} elseif (@array_key_exists('save', $_POST['action'])) {
$fields = $_POST['fields'];
$this->_errors = array();
if (!isset($fields['body']) || trim($fields['body']) == '') {
$this->_errors['body'] = __('Body is a required field');
} elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) {
$this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message']));
}
if (!isset($fields['title']) || trim($fields['title']) == '') {
$this->_errors['title'] = __('Title is a required field');
}
if (trim($fields['type']) != '' && preg_match('/(index|404|403)/i', $fields['type'])) {
$haystack = strtolower($fields['type']);
if (preg_match('/\\bindex\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = 'index' LIMIT 1"))) {
$this->_errors['type'] = __('An index type page already exists.');
} elseif (preg_match('/\\b404\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = '404' LIMIT 1"))) {
$this->_errors['type'] = __('A 404 type page already exists.');
} elseif (preg_match('/\\b403\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = '403' LIMIT 1"))) {
$this->_errors['type'] = __('A 403 type page already exists.');
}
}
if (empty($this->_errors)) {
## Manipulate some fields
//$fields['sortorder'] = $this->_Parent->Database->fetchVar('next', 0, "SELECT MAX(sortorder) + 1 as `next` FROM `tbl_pages` LIMIT 1");
//
//if(empty($fields['sortorder']) || !is_numeric($fields['sortorder'])) $fields['sortorder'] = 1;
$autogenerated_handle = false;
if (trim($fields['handle']) == '') {
$fields['handle'] = $fields['title'];
$autogenerated_handle = true;
}
$fields['handle'] = Lang::createHandle($fields['handle']);
if ($fields['params']) {
$fields['params'] = trim(preg_replace('@\\/{2,}@', '/', $fields['params']), '/');
}
## Clean up type list
$types = preg_split('/,\\s*/', $fields['type'], -1, PREG_SPLIT_NO_EMPTY);
$types = @array_map('trim', $types);
unset($fields['type']);
//if(trim($fields['type'])) $fields['type'] = preg_replace('/\s*,\s*/i', ', ', $fields['type']);
//else $fields['type'] = NULL;
## Manipulate some fields
$fields['parent'] = $fields['parent'] != 'None' ? $fields['parent'] : NULL;
$fields['data_sources'] = @implode(',', $fields['data_sources']);
$fields['events'] = @implode(',', $fields['events']);
$fields['path'] = NULL;
if ($fields['parent']) {
$fields['path'] = $this->_Parent->resolvePagePath(intval($fields['parent']));
}
$new_filename = trim(str_replace('/', '_', $fields['path'] . '_' . $fields['handle']), '_');
$current = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages` WHERE `id` = '{$page_id}' LIMIT 1");
$current_filename = $current['path'] . '_' . $current['handle'];
$current_filename = trim(str_replace('/', '_', $current_filename), '_');
## Duplicate
if ($this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages` \r\n\t\t\t\t\t\t\t\t\t\t WHERE `handle` = '" . $fields['handle'] . "' \r\n\t\t\t\t\t\t\t\t\t\t AND `id` != '{$page_id}' \r\n\t\t\t\t\t\t\t\t\t\t AND `path` " . ($fields['path'] ? " = '" . $fields['path'] . "'" : ' IS NULL') . " \r\n\t\t\t\t\t\t\t\t\t\t LIMIT 1")) {
if ($autogenerated_handle) {
$this->_errors['title'] = __('A page with that title %s already exists', array($fields['parent'] ? __('and parent') : ''));
} else {
$this->_errors['handle'] = __('A page with that handle %s already exists', array($fields['parent'] ? __('and parent') : ''));
}
} else {
## Write the file
if (!($write = General::writeFile(PAGES . "/{$new_filename}.xsl", $fields['body'], $this->_Parent->Configuration->get('write_mode', 'file')))) {
$this->pageAlert(__('Page could not be written to disk. Please check permissions on <code>/workspace/pages</code>.'), Alert::ERROR);
} else {
if ($new_filename != $current_filename) {
@unlink(PAGES . "/{$current_filename}.xsl");
}
## No longer need the body text
unset($fields['body']);
## Insert the new data
if (!$this->_Parent->Database->update($fields, 'tbl_pages', "`id` = '{$page_id}'")) {
$this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your <a href="%s">activity log</a>.', array(URL . '/symphony/system/log/')), Alert::ERROR);
} else {
$this->_Parent->Database->delete('tbl_pages_types', " `page_id` = '{$page_id}'");
if (is_array($types) && !empty($types)) {
foreach ($types as $type) {
$this->_Parent->Database->insert(array('page_id' => $page_id, 'type' => $type), 'tbl_pages_types');
}
}
## TODO: Fix Me
//.........这里部分代码省略.........
示例14: __applyFormatting
protected function __applyFormatting($data, $validate = false, &$errors = NULL)
{
if ($this->get('formatter')) {
if (isset($this->_ParentCatalogue['entrymanager'])) {
$tfm = $this->_ParentCatalogue['entrymanager']->formatterManager;
} else {
$tfm = new TextformatterManager($this->_engine);
}
$formatter = $tfm->create($this->get('formatter'));
$result = $formatter->run($data);
}
if ($validate === true) {
include_once TOOLKIT . '/class.xsltprocess.php';
if (!General::validateXML($result, $errors, false, new XsltProcess())) {
$result = html_entity_decode($result, ENT_QUOTES, 'UTF-8');
$result = $this->__replaceAmpersands($result);
if (!General::validateXML($result, $errors, false, new XsltProcess())) {
$result = $formatter->run(General::sanitize($data));
if (!General::validateXML($result, $errors, false, new XsltProcess())) {
return false;
}
}
}
}
return $result;
}
示例15: __actionEdit
public function __actionEdit()
{
$this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL;
if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) {
$fields = $_POST['fields'];
//$this->errors = array();
if (!isset($fields['name']) || trim($fields['name']) == '') {
$this->errors->name = __('Name is a required field.');
}
if (!isset($fields['template']) || trim($fields['template']) == '') {
$this->errors->template = __('XSLT is a required field.');
} elseif (!General::validateXML($fields['template'], $errors)) {
$fragment = $this->createDocumentFragment();
$fragment->appendChild(new DOMText(__('This document is not well formed. The following error was returned: ')));
$fragment->appendChild($this->createElement('code', $errors->current()->message));
$this->errors->template = $fragment;
}
if (!$this->errors->valid()) {
$fields['name'] = Lang::createFilename($fields['name']);
if (General::right($fields['name'], 4) != '.xsl') {
$fields['name'] .= '.xsl';
}
$file = UTILITIES . '/' . $fields['name'];
// TODO: Does it really need stripslashed? Funky.
$fields['template'] = stripslashes($fields['template']);
##Duplicate
if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) {
$this->errors->name = __('A Utility with that name already exists. Please choose another.');
} elseif ($this->_context[0] == 'new' && is_file($file)) {
$this->errors->name = __('A Utility with that name already exists. Please choose another.');
} elseif (!($write = General::writeFile($file, $fields['template'], Symphony::Configuration()->core()->symphony->{'file-write-mode'}))) {
$this->alerts()->append(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), AlertStack::SUCCESS);
} else {
## Remove any existing file if the filename has changed
if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) {
General::deleteFile(UTILITIES . '/' . $this->_existing_file);
}
## FIXME: Fix this delegate
###
# Delegate: Edit
# Description: After saving the asset, the file path is provided.
//Extension::notify('Edit', getCurrentPage(), array('file' => $file));
redirect(ADMIN_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
}
}
} elseif ($this->_context[0] == 'edit' && array_key_exists('delete', $_POST['action'])) {
## FIXME: Fix this delegate
###
# Delegate: Delete
# Description: Prior to deleting the asset file. Target file path is provided.
//Extension::notify('Delete', getCurrentPage(), array('file' => WORKSPACE . '/' . $this->_existing_file_rel));
$this->__actionDelete(UTILITIES . '/' . $this->_existing_file, ADMIN_URL . '/blueprints/components/');
}
}