Page MenuHomeDevCentral

No OneTemporary

diff --git a/json/JsonComposer.php b/json/JsonComposer.php
new file mode 100644
index 0000000..37da6e1
--- /dev/null
+++ b/json/JsonComposer.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * Nasqueron Tools
+ *
+ * JSON composer
+ *
+ * @package NasqueronTools
+ * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD
+ * @filesource
+ *
+ */
+
+/**
+ * Composes a JSON file
+ */
+class JsonComposer {
+ /**
+ * Gets a JSON representation from two arrays, one with the properties, the other with the values
+ *
+ * @param array $properties An array of the properties, each item a string
+ * @param array $data An array of the values, each item an array with the same amount of columns than the properties array, each item a value
+ * @return string the JSON representation
+ */
+ public static function fromKeysAndValuesArrays($properties, $data) {
+ $dataArray = [];
+ $countProperties = count($properties);
+
+ foreach ($data as $row) {
+ $rowProperties = $properties;
+ $delta = count($row) - $countProperties;
+ if ($delta < 0) {
+ //When we've more properties than values, we fill with empty strings.
+ $row += array_fill($countProperties + $delta, $delta * - 1, '');
+ } elseif ($delta > 0) {
+ //When we miss properties, adds property4, property5, property6, ...
+ for ($i = $countProperties ; $i < $delta + $countProperties ; $i ++) {
+ $rowProperties[] = "property$i";
+ }
+
+ }
+ $dataArray[] = array_combine($rowProperties, $row);
+ }
+ return json_encode($dataArray, JSON_PRETTY_PRINT);
+ }
+ }
diff --git a/json/_documents.xml b/json/_documents.xml
new file mode 100644
index 0000000..859e851
--- /dev/null
+++ b/json/_documents.xml
@@ -0,0 +1,7 @@
+<documents topic="json">
+ <document>
+ <article>excel2json</article>
+ <title>Excel to JSON converter</title>
+ <description>Converts an Excel sheet or a tab-separated file into a JSON document.</description>
+ </document>
+</documents>
diff --git a/json/excel2json.php b/json/excel2json.php
new file mode 100644
index 0000000..08cbd00
--- /dev/null
+++ b/json/excel2json.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * Nasqueron Tools
+ *
+ * Excel to JSON converter
+ *
+ * @package NasqueronTools
+ * @subpackage JSON
+ * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD
+ * @filesource
+ *
+ */
+
+$data = isset($_REQUEST['data']) ? $_REQUEST['data'] : '';
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
+$outputAsObject = false;
+
+if ($data !== '') {
+ $outputAsObject = array_key_exists('json-output', $_REQUEST) && ($_REQUEST['json-output'] == 'object');
+
+ $dataArray = [];
+ $rows = explode("\n", $data);
+
+ //Allows user to add an extra line (default behavior from Excel by the way)
+ if (end($rows) === '') {
+ array_pop($rows);
+ }
+
+ foreach ($rows as $row) {
+ $row = trim($row, "\r");
+ $dataArray[] = explode("\t", $row);
+ }
+ if ($outputAsObject) {
+ require 'JsonComposer.php';
+
+ //First line as properties
+ $properties = array_shift($dataArray);
+ if ($properties === ['']) {
+ //If the first line is empty, we don't assume an unique empty string property,
+ //but we assume the user wants to autofill property0, property1, property2, etc.
+ $properties = [];
+ }
+
+ $json = JsonComposer::fromKeysAndValuesArrays($properties, $dataArray);
+ } else {
+ $json = json_encode($dataArray, JSON_PRETTY_PRINT);
+ }
+
+ $url = get_url('dl.php');
+ echo "<form method=\"post\" action=\"$url?contentType=application%2Fjson\">\n";
+ echo " <h2>Result</h2>\n";
+ echo ' <div class="row">', "\n\t", '<div class="twelve columns"><textarea id="result" name="result" rows="8">',
+ $json, '</textarea></div>', "\n", '</div>';
+ echo ' <div class="row collapse">
+ <div class="one mobile-one columns">
+ <span class="prefix">Save as</span>
+ </div>
+ <div class="four mobile-two columns">
+ <input type="text" name="filename" id="filename" value="data.json" />
+ </div>
+ <div class="one mobile-one columns end">
+ <input type="submit" class="button expand postfix" name="action" value="Download" />
+ </div>
+ </div>
+</form>';
+}
+
+?>
+<form method="post">
+ <h2>Source</h2>
+ <div class="row"><div class="twelve columns">
+ <label for="data">Paste cells from your spreadsheet application or introduces tab separated values:</label>
+ </div></div>
+ <div class="row"><div class="twelve columns">
+ <textarea id="data" name="data" rows="8"><?= $data ?></textarea>
+ </div></div>
+ <div class="row"><div class="twelve columns">
+ <label for="json-output-array"><input type="radio" name="json-output" id="json-output-array" value="array"<?= !$outputAsObject ? ' checked="true"' : '' ?> /> Convert rows to arrays. The first line is already data.</label>
+ <label for="json-output-object"><input type="radio" name="json-output" id="json-output-object" value="object"<?= $outputAsObject ? ' checked="true"' : '' ?> /> Convert rows to objects. The first line contains the properties names.</label>
+ </div></div>
+ <div class="row"><div class="twelve columns">
+ <input type="submit" rows="8" value="Convert" class="button" />
+ </div></div>
+</form>
diff --git a/json/index.html b/json/index.html
new file mode 100644
index 0000000..d997151
--- /dev/null
+++ b/json/index.html
@@ -0,0 +1,4 @@
+<h2>JSON tools</h2>
+<ul>
+ <li><strong><a href="/json/excel2json">Excel to JSON</a></strong> — Converts an excel sheet or a tab-separated data file into a JSON document.</li>
+</ul>
diff --git a/themes/RalfFallsIntoFoundation/footer.php b/themes/RalfFallsIntoFoundation/footer.php
index 7837808..813e803 100755
--- a/themes/RalfFallsIntoFoundation/footer.php
+++ b/themes/RalfFallsIntoFoundation/footer.php
@@ -1,84 +1,87 @@
</div></section>
<!-- Footer -->
<footer><div class="row">
<div class="twelve columns"><hr />
<div class="row">
<div class="three columns site-description">
<p><img src="/images/Nasqueron.png" width="80px" /></p>
<p><strong>Nasqueron</strong> is a community of developers <span class="ampersand">&</span> creative people.</p>
<hr />
<p><strong>Nasqueron Tools</strong> is a collection of small utilities, gadgets <span class="ampersand">&</span> scripts to perform daily tasks.</p>
</div>
<div class="three columns">
<dl>
<dt>Wikimedia dev</dt>
<dd><a href="/wikimedia/dev/feeds/">Gerrit activity feeds</a></dd>
<!--<dd>RSS generator</dd>-->
<dt>Wikimedia Writing Tools</dt>
<dd><a href="/wikimedia/write/sourcetemplatesgenerator/">Source templates generator</a></dd>
<dt>Finger</dt>
<dd><a href="/finger">Finger client</a></dd>
<dd><a href="/finger/thimbl">Thimbl client</a></dd>
<dt>µblogging</dt>
<dd><a href="/microblogging/twitterpoints">Twitter Points</a></dd>
</dl>
</div>
<div class="three columns">
<dl>
- <dt>CSS</dt>
- <dd><a href="/css/media-queries-generator">Media queries generator</a></dd>
-
<dt>Lists</dt>
<dd><a href="/lists/operations">Lists operations</a></dd>
<dd><a href="/lists/replace">Lists RegExp replace</a></dd>
+ <dt>CSS</dt>
+ <dd><a href="/css/media-queries-generator">Media queries generator</a></dd>
+
+ <dt>JSON</dt>
+ <dd><a href="/json/excel2json">Excel to JSON converter</a></dd>
+
<dt>Color</dt>
<dd><a href="/color/screen/">Random color screen</a></dd>
<dd><a href="/color/screen/879497">Gray-blue screen</a></dd>
</dl>
</div>
<div class="three columns">
<dl>
<dt>Gadgets</dt>
<dd><a href="/gadgets/motd-variations">MOTD in Jive <span class="ampersand">&</span> Valspeak</a></dd>
<dd><a href="/gadgets/text-variations">Letters variation</a></dd>
<dt>Network</dt>
<dd><a href="/network/mx">MX</a></dd>
<dt>Start pages</dt>
<dd><a href="/lex">Lex</a></dd>
</dl>
</div>
</div>
</div>
<div class="twelve columns"><hr />
<div class="row extrainfos">
<div class="six columns">
<p><i class="general foundicon-settings"></i> <strong>Options:</strong> <a href="javascript:SetUITonality('dark');">dark mode</a> | <a href="javascript:SetUITonality('light');">light mode</a></p>
</div>
<div class="six columns">
<p class="right"><i class="general foundicon-flag"></i> <strong>Git revision:</strong> <?= substr(`git rev-parse HEAD`, 0, 7) ?> | <strong>Version:</strong> alpha preview</p>
</div>
</div>
<div class="row extrainfos">
<div class="six columns">
<p><i class="general foundicon-globe"></i> <strong>Crafted by</strong> <a href="http://www.dereckson.be/">Dereckson</a> | <strong>Powered by</strong> <a href="http://keruald.sf.net">Keruald/Pluton</a> <span class="ampersand">&</span> <a href="http://foundation.zurb.com/">Foundation</a>.</p>
</div>
<div class="six columns">
<p class="right">“For water, though supposedly incompressible, is not entirely so.”</p>
</div>
</div>
</div>
</div></footer>
<script src="/javascripts/foundation.min.js"></script>
<script src="/javascripts/jquery.cookie.js"></script>
<script src="/javascripts/app.js"></script>
<?= $document->footer ?>
</body>
</html>

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 09:14 (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259908
Default Alt Text
(9 KB)

Event Timeline