summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Morrison2012-11-27 03:26:33 (GMT)
committer Dan Morrison2012-11-27 03:26:33 (GMT)
commit0f1984f066322c22cb73b5b348a2e99e481e1f7f (patch)
tree4842bd67994cadcc3bac58569c912e6099387f12
parentd2e7892ab6ba55f28b0998702368b9bda30d0ce6 (diff)
Added a selectbox not a file path for XSL. Added upload for managing your XSL. tweaked the available default formatters. Added file upload support to process uploaded XML
-rwxr-xr-xxsl/mozDss5.xsl547
-rw-r--r--xsl/xmlverbatimwrapper.xsl2
-rw-r--r--xsl_formatter.module116
3 files changed, 658 insertions, 7 deletions
diff --git a/xsl/mozDss5.xsl b/xsl/mozDss5.xsl
new file mode 100755
index 0000000..2ca92f2
--- /dev/null
+++ b/xsl/mozDss5.xsl
@@ -0,0 +1,547 @@
+<!--
+
+ ***** BEGIN LICENSE BLOCK *****
+ - Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ -
+ - The contents of this file are subject to the Mozilla Public License Version
+ - 1.1 (the "License"); you may not use this file except in compliance with
+ - the License. You may obtain a copy of the License at
+ - http://www.mozilla.org/MPL/
+ -
+ - Software distributed under the License is distributed on an "AS IS" basis,
+ - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ - for the specific language governing rights and limitations under the
+ - License.
+ -
+ - The Original Code is mozilla.org code.
+ -
+ - The Initial Developer of the Original Code is
+ - Netscape Communications Corporation.
+ - Portions created by the Initial Developer are Copyright (C) 2002
+ - the Initial Developer. All Rights Reserved.
+ -
+ - Contributor(s):
+ - Jonas Sicking <sicking@bigfoot.com> (Original author)
+ -
+ - Alternatively, the contents of this file may be used under the terms of
+ - either the GNU General Public License Version 2 or later (the "GPL"), or
+ - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ - in which case the provisions of the GPL or the LGPL are applicable instead
+ - of those above. If you wish to allow use of your version of this file only
+ - under the terms of either the GPL or the LGPL, and not to allow others to
+ - use your version of this file under the terms of the MPL, indicate your
+ - decision by deleting the provisions above and replace them with the notice
+ - and other provisions required by the LGPL or the GPL. If you do not delete
+ - the provisions above, a recipient may use your version of this file under
+ - the terms of any one of the MPL, the GPL or the LGPL.
+ -
+ - ***** END LICENSE BLOCK *****
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ >
+
+ <xsl:param name="selectedNodes" select="@comment()"/>
+ <xsl:param name="scalarExpr" select="@comment()"/>
+
+<!-- The following is not used because of a bug in Mozilla :( -->
+<!--
+ <xsl:key name="kattPref" match="@*"
+ use="concat(generate-id(..), '|', substring-before(., ':'))"/>
+-->
+ <xsl:output method="html"/>
+ <xsl:template match="/">
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <style>
+ .mozDss5 {
+ font-family: 'Verdana', sans-serif;
+ width: 100%;
+ margin: 0;
+ padding: 0;
+ }
+
+
+ .mozDss5 img {
+ float: left;
+ margin: 0.5em;
+ }
+
+ .mozDss5 table {
+ border-spacing: 0;
+ margin: 0;
+ width:auto;
+ }
+
+ .mozDss5 td {
+ padding: 0;
+ border:none;
+ }
+
+ .mozDss5 .markup {
+ color: blue
+ }
+
+ .mozDss5 .elemname {
+ color: #990000;
+ }
+
+ .mozDss5 .attrname {
+ color: #990000;
+ font-weight: bold;
+ }
+
+ .mozDss5 .namespace {
+ color: red;
+ font-weight: bold;
+ }
+ .mozDss5 .attrvalue {
+ color: black;
+ font-weight: bold;
+ }
+
+ .mozDss5 .text {
+ color: black;
+ font-weight: bold;
+ }
+
+ .mozDss5 .indent {
+ margin-left: 1em;
+ }
+
+ .mozDss5 .comment {
+ color: #888888;
+ font-style: italic;
+ }
+
+ .mozDss5 .pi {
+ color: blue;
+ }
+
+ .mozDss5 .expander > div {
+ width: 1em;
+ }
+
+ .mozDss5 .expander {
+ cursor: default;
+ -moz-user-select: none;
+ vertical-align: top;
+ text-align: center;
+ margin: 0 0 0 -1em;
+ }
+
+ .mozDss5 .expander-closed .expander-content {
+ display: none;
+ }
+
+ .mozDss5 .se {background-Color:yellow}
+ </style>
+ <script>
+ <xsl:comment><![CDATA[
+
+function clicked(event) {
+ try {
+ var thisNode = event.target;
+ var par = event.target.parentNode;
+ if (thisNode.nodeName == 'TD' && thisNode.className == 'expander') {
+ if (par.parentNode.className == 'expander-closed') {
+ par.parentNode.className = '';
+ event.target.data = '-';
+ }
+ else {
+ par.parentNode.className = 'expander-closed';
+ event.target.data = '+';
+ }
+ }
+ } catch (e) {
+ }
+}
+
+]]></xsl:comment>
+ </script>
+ </head>
+ <body bgcolor="#E9FEFE" ID="theBody" title="{$scalarExpr}" onclick="clicked(event) ">
+ <xsl:apply-templates/>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="*">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <div class="indent">
+ <span class="markup">&lt;</span>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>elemname</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <span class="{$class}">
+ <xsl:value-of select="name(.)"/>
+ </span>
+
+ <xsl:call-template name="findNamespace"/>
+
+ <xsl:apply-templates select="@*"/>
+ <span class="markup">/></span>
+ </div>
+ </xsl:template>
+
+ <xsl:template match="*[text()]">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>elemname</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="indent">
+ <span class="markup">&lt;</span>
+ <span class="{$class}">
+ <xsl:value-of select="name(.)"/>
+ </span>
+
+ <xsl:call-template name="findNamespace"/>
+
+ <xsl:apply-templates select="@*"/>
+ <span class="markup">></span>
+ <!--<span class="text">
+ <xsl:value-of select="."/> -->
+ <xsl:apply-templates/>
+ <!--</span>-->
+ <span class="markup">&lt;/</span>
+ <span class="elemname">
+ <xsl:value-of select="name(.)"/>
+ </span>
+ <span class="markup">></span>
+ </div>
+ </xsl:template>
+
+ <xsl:template match="*[* or processing-instruction() or comment()
+ or string-length(text()) > 50]" priority="10">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>elemname</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+
+ <table class="mozDss5">
+ <tr>
+ <td class="expander">
+ -
+ <div/>
+ </td>
+ <td>
+ <span class="markup">&lt;</span>
+ <span class="{$class}">
+ <xsl:value-of select="name(.)"/>
+ </span>
+ <xsl:call-template name="findNamespace"/>
+ <xsl:apply-templates select="@*"/>
+ <span class="markup">></span>
+ <div class="expander-content">
+ <xsl:apply-templates/>
+ </div>
+ <span class="markup">&lt;/</span>
+ <span class="elemname">
+ <xsl:value-of select="name(.)"/>
+ </span>
+ <span class="markup">></span>
+ </td>
+ </tr>
+ </table>
+ </xsl:template>
+ <xsl:template match="@*">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+
+ <xsl:variable name="vPos" select="position()"/>
+
+ <xsl:variable name="vPref" select="substring-before(name(), ':')"/>
+
+ <xsl:if test="$vPref
+ and
+ not(../@*[position() &lt; $vPos]
+ [substring-before(name(), ':')
+ = $vPref]
+ )">
+ <xsl:call-template name="findNamespace"/>
+ </xsl:if>
+
+<!-- The following is not used because of a bug in Mozilla :( -->
+
+<!--
+ <xsl:if test=
+ "generate-id()
+ =
+ generate-id(key('kattPref',
+ concat(generate-id(..), '|', substring-before(., ':'))
+ )[1]
+ )">
+ <xsl:call-template name="findNamespace"/>
+ </xsl:if>
+-->
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>attrname</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="class2">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>markup</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="class3">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>attrvalue</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:text> </xsl:text>
+ <span class="{$class}">
+ <xsl:value-of select="name(.)"/>
+ </span>
+ <span class="{$class2}">="</span>
+ <span class="{$class3}">
+ <!-- <xsl:value-of select="."/> -->
+ <xsl:call-template name="replaceAmpersands">
+ <xsl:with-param name="vString" select="string(.)"/>
+ </xsl:call-template>
+ </span>
+ <span class="{$class2}">"</span>
+ </xsl:template>
+
+ <xsl:template match="text()">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>text</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <span class="{$class}">
+ <!-- <xsl:value-of select="."/> -->
+ <xsl:call-template name="replaceAmpersands">
+ <xsl:with-param name="vString" select="string(.)"/>
+ </xsl:call-template>
+ </span>
+ </xsl:template>
+
+ <xsl:template match="processing-instruction()">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>indent pi</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="{$class}">
+
+ &lt;?
+ <xsl:value-of select="name(.)"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="."/>
+?>
+
+ </div>
+ </xsl:template>
+
+ <xsl:template match="processing-instruction()[string-length(.) > 50]">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>pi</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="class2">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>indent expander-content</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <table>
+ <tr>
+ <td class="expander">
+ -
+ <div/>
+ </td>
+ <td class="{$class}">
+
+ &lt;?
+ <xsl:value-of select="name(.)"/>
+ <div class="{$class2}">
+ <xsl:value-of select="."/>
+ </div>
+ <xsl:text>?></xsl:text>
+ </td>
+ </tr>
+ </table>
+ </xsl:template>
+
+ <xsl:template match="comment()">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>comment indent</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <div class="{$class}">
+ &lt;!--
+ <xsl:value-of select="."/>
+ -->
+ </div>
+ </xsl:template>
+
+ <xsl:template match="comment()[string-length(.) > 50]">
+ <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
+
+ <xsl:variable name="class">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>comment</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="class2">
+ <xsl:choose>
+ <xsl:when test="$belongs = 0">se</xsl:when>
+ <xsl:otherwise>indent expander-content</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <table>
+ <tr>
+ <td class="expander">
+ -
+ <div/>
+ </td>
+ <td class="{$class}">
+ &lt;!--
+ <div class="{$class2}">
+ <xsl:value-of select="."/>
+ </div>
+ -->
+ </td>
+ </tr>
+ </table>
+ </xsl:template>
+
+ <xsl:template name="findNamespace">
+
+ <xsl:variable name="vName" select="substring-before(name(), ':')"/>
+ <xsl:variable name="vUri" select="namespace-uri(.)"/>
+
+ <xsl:variable name="vAncestNamespace">
+ <xsl:call-template name="findAncNamespace">
+ <xsl:with-param name="pName" select="$vName"/>
+ <xsl:with-param name="pUri" select="$vUri"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:if test="not(number($vAncestNamespace))">
+ <xsl:if test="namespace-uri()
+ or
+ not(generate-id()
+ =
+ generate-id(../@*[name()
+ =
+ name(current())]
+ )
+ )">
+ <xsl:if test="parent::* or namespace-uri() or contains(name(), ':')">
+ <xsl:text> </xsl:text>
+ <span class="namespace">
+ <xsl:value-of select="'xmlns'"/>
+ <xsl:if test="contains(name(), ':')">
+ <xsl:value-of select="concat(':', $vName)"/>
+ </xsl:if>
+ </span>
+ <span class="markup">="</span>
+ <span class="namespace">
+ <xsl:value-of select="namespace-uri()"/>
+ </span>
+ <span class="markup">"</span>
+ </xsl:if>
+ </xsl:if>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="findAncNamespace">
+ <xsl:param name="pNode" select="."/>
+ <xsl:param name="pName" select="substring-before(name(), ':')"/>
+ <xsl:param name="pUri" select="namespace-uri(.)"/>
+
+ <xsl:choose>
+ <xsl:when test="not($pNode/parent::*)
+ and not($pName) and not($pUri)">1</xsl:when>
+ <xsl:when test="not($pNode/parent::*)">0</xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="vSamePrefs"
+ select="number($pName
+ = substring-before(name($pNode/..), ':')
+ )"/>
+
+ <xsl:variable name="vSameUris"
+ select="number($pUri = namespace-uri($pNode/..))"/>
+
+ <xsl:choose>
+ <xsl:when test="$vSamePrefs and not($vSameUris)">0</xsl:when>
+ <xsl:when test="not($vSamePrefs)">
+ <xsl:call-template name="findAncNamespace">
+ <xsl:with-param name="pNode" select="$pNode/.."/>
+ <xsl:with-param name="pName" select="$pName"/>
+ <xsl:with-param name="pUri" select="$pUri"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>1</xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+
+ <xsl:template name="replaceAmpersands">
+ <xsl:param name="vString"/>
+
+ <xsl:variable name="vAmp">&amp;</xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="contains($vString, $vAmp)">
+ <xsl:value-of select="substring-before($vString, $vAmp)"/>
+ <xsl:value-of select="concat($vAmp, 'amp;')"/>
+ <xsl:call-template name="replaceAmpersands">
+ <xsl:with-param name="vString"
+ select="substring-after($vString, $vAmp)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$vString"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+</xsl:stylesheet> \ No newline at end of file
diff --git a/xsl/xmlverbatimwrapper.xsl b/xsl/xmlverbatimwrapper.xsl
index e3a06c8..48714f0 100644
--- a/xsl/xmlverbatimwrapper.xsl
+++ b/xsl/xmlverbatimwrapper.xsl
@@ -65,6 +65,8 @@ Brought the external css into the head to avoid relative link issues.
.xmlverb-pi-content { color: #006666; font-style: italic }
</style>
+ <style type="text/css" media="print">@import url("<xsl:value-of select="$base"/>/xmlverbatim.css");</style>
+
</head>
<body class="xmlverb-default">
<tt>
diff --git a/xsl_formatter.module b/xsl_formatter.module
index c3b6428..fe121d7 100644
--- a/xsl_formatter.module
+++ b/xsl_formatter.module
@@ -41,16 +41,18 @@
* @version 2012-11-27 (1:00AM -3:30AM)
*/
+
/**
* Implements hook_field_formatter_info().
*
- * Ceclares the existance of this formatter.
+ * Declares the existance of this formatter.
+ * We can do similar things to local textareas, remote URLs, or uploaded files!
*/
function xsl_formatter_field_formatter_info() {
return array(
'xsl_formatter' => array(
'label' => t('Transformed by XSL'),
- 'field types' => array('text_long', 'link_field'),
+ 'field types' => array('text_long', 'link_field', 'file'),
'settings' => array(
'xsl_path' => 'xsl/xmlverbatim.xsl',
'xsl_params' => '',
@@ -79,12 +81,37 @@ function xsl_formatter_field_formatter_settings_summary($field, $instance, $view
function xsl_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
+
+ // Originally text, try a drop-down instead
+ /*
$element['xsl_path'] = array(
'#title' => t('XSL path'),
'#type' => 'textfield',
'#default_value' => $settings['xsl_path'],
'#element_validate' => array('xsl_formatter_xsl_path_validate'),
'#description' => t("Path to the location of the XSL file. Search will be made relative to the module directory, the site directory and the file directory. eg <code>xsl/xmlverbatimwrapper.xsl</code>, <code>xsl/prettyprint.xsl</code>"),
+ '#autocomplete_path' => 'admin/xsl_path'
+ );
+ */
+ $xsls = xsl_formatter_enumerate_xsls();
+ $element['xsl_path'] = array(
+ '#title' => t('XSL path'),
+ '#type' => 'select',
+ '#default_value' => $settings['xsl_path'],
+ '#element_validate' => array('xsl_formatter_xsl_path_validate'),
+ '#description' => t("Path to the location of the XSL file. Search will be made relative to the files/xsl directory, then the module directory."),
+ '#options' => $xsls,
+ );
+
+ // file upload needs an explicit name. This is horrid sorry
+ $upload_field_id = 'files[' . drupal_clean_css_identifier("files[fields][{$instance['field_name']}][settings_edit_form][settings][xsl_upload]") . ']';
+ $element['xsl_upload'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload XSL file'),
+ '#maxlength' => 40,
+ '#description' => t("This will be placed in your files/xsl folder where it can be found and re-used."),
+ '#element_validate' => array('xsl_formatter_xsl_upload_validate'),
+ '#name' => $upload_field_id,
);
$module_path = drupal_get_path('module', 'xsl_formatter');
$element['xsl_params'] = array(
@@ -132,6 +159,45 @@ function xsl_formatter_xsl_params_validate($element, &$form_state, $form) {
}
/**
+ * If we upload our own xsl, Make sure it gets saved.
+ *
+ * Place it in the public xsl foilder and refer to it.
+ */
+function xsl_formatter_xsl_upload_validate($element, &$form_state, $form) {
+ // Check for a new uploaded xsl.
+ // Figure out what the big ID was. This is wierd.
+ $upload_field_id = 'files-' . substr($element['#id'], strlen('edit-'));
+
+ // Get it. Temporary at first.
+ $validators = array('file_validate_extensions' => array('xsl','xslt'));
+ $file = file_save_upload($upload_field_id, $validators);
+
+ if (!empty($file)) {
+ // File upload was attempted.
+ if ($file) {
+ $save_dir = "public://xsl";
+ file_prepare_directory($save_dir, FILE_CREATE_DIRECTORY);
+ $save_filepath = $save_dir . '/' . $file->filename;
+ $filename = file_unmanaged_copy($file->uri, $save_filepath, FILE_EXISTS_REPLACE);
+
+ // Set xsl_path to the newly uploaded value.
+ // The #parents array is important.
+ // Find the nearby xsl_path element with the same ancestry as me.
+ $parents = $element['#parents'];
+ array_pop($parents);
+ array_push($parents, 'xsl_path');
+ $xsl_path_element = array('#parents' => $parents);
+ form_set_value($xsl_path_element, $save_filepath, $form_state);
+ }
+ else {
+ // File upload failed.
+ form_set_error('xsl_upload', t('The xsl could not be uploaded.'));
+ }
+ }
+}
+
+
+/**
* Implements hook_field_formatter_view().
*
* Does the process here, to generate the result.
@@ -145,12 +211,19 @@ function xsl_formatter_field_formatter_view($entity_type, $entity, $field, $inst
$data = @$item['value'];
$xml_doc = new domdocument;
+ // Alternate field types. Local data (valus) is easiest, but
// If the field type is a link, go get that data now
// DESPERATELY need caching or something here.
if ($field['type'] == 'link_field') {
$url = url($item['url'], $item);
$data = file_get_contents($url);
}
+ // Or files, why not?
+ if ($field['type'] == 'file') {
+ dpm($item);
+# $url = url($item['url'], $item);
+ $data = file_get_contents($item['uri']);
+ }
try {
// Tricky to catch errors.
@@ -165,9 +238,12 @@ function xsl_formatter_field_formatter_view($entity_type, $entity, $field, $inst
}
// XML Loaded OK. Now load the stylesheet.
- $xsl_doc = xsl_formatter_get_xml_doc($display['settings']['xsl_path']);
+ $xsl_path = $display['settings']['xsl_path'];
+ $xsl_doc = xsl_formatter_get_xml_doc($xsl_path);
// Pass through any params that the XSLT may want.
- $params = json_decode($display['settings']['xsl_params']);
+ $params = (array)json_decode($display['settings']['xsl_params']);
+ // 'base' can be used for supporting relative css links.
+ $params['base'] = url(dirname($xsl_doc->documenturi));
// Transform!
$result = xsl_formatter_xmldoc_plus_xsldoc($xml_doc, $xsl_doc, $params);
}
@@ -220,6 +296,32 @@ function theme_xsl_formatter($variables) {
return $variables['result'];
}
+/**
+ * Return a list of xsl files, as found in the search locations
+ * Over-engineerd for now, anticipating 'module:// as a file scheme
+ * and keeping the UI simpler (?)
+ */
+function xsl_formatter_enumerate_xsls() {
+ $paths = array('public://xsl', 'module://xsl_formatter/xsl');
+ $found = array();
+ foreach ($paths as $base) {
+ $label = $base;
+
+ // Just me being cute here...
+ if (file_uri_scheme($base) == 'module') {
+ $target_path = file_uri_target($base);
+ $split_path = explode('/', $target_path);
+ $module_name = array_shift($split_path);
+ $base = drupal_get_path('module' , $module_name) .'/'. join('/', $split_path);
+ }
+
+ $files = file_scan_directory($base, '/.*\.xsl[t]?/');
+ foreach ($files as $file) {
+ $found[$file->uri] = $label .'/'. $file->filename;
+ }
+ }
+ return $found;
+}
/////////////////////////
// XML utilities below.
@@ -253,17 +355,17 @@ function xsl_formatter_get_xml_doc($xml_file, $description = "XML file") {
}
// Check if and where filepath can be found.
- // Search first under full path, then module dir, then under files dir.
+ // Search first under full path, then under files dir, then module dir.
# TODO - check if this could be used as an attack vector?
# Sanitize the fetch path.
$xml_filepath = $xml_file;
if (!is_file($xml_filepath)) {
- $xml_filepath = drupal_get_path('module', 'xsl_formatter') . "/$xml_file";
+ $xml_filepath = 'public://' . $xml_file;
}
if (!is_file($xml_filepath)) {
- $xml_filepath = 'public://' . $xml_file;
+ $xml_filepath = drupal_get_path('module', 'xsl_formatter') . "/$xml_file";
}
if (is_file($xml_filepath)) {