Export webuilder snippets to folder and textfile structure
Moderator: kfury77
Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.
Please try to follow these guidelines. This will help to receive faster and more accurate response.
- Check the Support section of the corresponding product first. Chances are you will find your answer there;
- Do not create new topics for already reported problems. Add your comments to the existing topics instead;
- Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
- Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
- Include the version number of the software you are using;
- This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;
-
- Posts: 9
- Joined: Thu Oct 07, 2010 10:14 pm
Export webuilder snippets to folder and textfile structure
Is there a way to export the snippets in the "library.xml" file to a folder/subfolder/textfile structure?
I am trying place all my snippets from all my editors into one place (Source Code Library).
Doing it manually is taking a very long time.
If it's not possible, are there any pointers to extract:
The snippet folder
The snippet subfolder
The snippet title
The snippet "Insert before caret"
(I don't use "Shortcut key" , "Callword" and "Insert after caret")
I am maybe able to create a macro outside webuilder which will cycle through the XML file and convert it into the folder/subfolder -textfile structure. (or maybe using a tool/utility? Any suggestions/tips are very welcome!)
Example:
|-folder: PHP
|--_subfolder: Strings
|------snippet textfile: explode-example-1.txt
I am trying place all my snippets from all my editors into one place (Source Code Library).
Doing it manually is taking a very long time.
If it's not possible, are there any pointers to extract:
The snippet folder
The snippet subfolder
The snippet title
The snippet "Insert before caret"
(I don't use "Shortcut key" , "Callword" and "Insert after caret")
I am maybe able to create a macro outside webuilder which will cycle through the XML file and convert it into the folder/subfolder -textfile structure. (or maybe using a tool/utility? Any suggestions/tips are very welcome!)
Example:
|-folder: PHP
|--_subfolder: Strings
|------snippet textfile: explode-example-1.txt
Re: Export webuilder snippets to folder and textfile structu
Hi dragonetti, found any work around on this yet?
When in doubt, use Brute Force 

-
- Posts: 9
- Joined: Thu Oct 07, 2010 10:14 pm
Re: Export webuilder snippets to folder and textfile structu
I am still working on it, I hope to have something this week. Can't promise anything though...
If I get somewhere I'll post update here.
(tips, hints, workarounds are very welcome...)
If I get somewhere I'll post update here.
(tips, hints, workarounds are very welcome...)
Re: Export webuilder snippets to folder and textfile structu
There is no direct way to export the Library to files. As you have correctly noticed it is possible to create a script that can parse the Library. For example, try this PHP script:
Updated:
I do not have a huge Library on my computer, but I hope it will work. The script and the library.xml file should be in the same directory.
Updated:
Code: Select all
<?php
$rawContent = file_get_contents('library.xml');
$xmlContent = simplexml_load_string($rawContent);
// Quick & dirty way to convert XML to array
$jsonData = json_encode($xmlContent);
$arrayData = json_decode($jsonData, true);
// Our Library parse function.
function parseLibrary(array $array, array $depth)
{
$ext = '.txt';
foreach ($array as $folder)
{
if (isset($folder['Title']) == true) $depth[] = $folder['Title'];
if (isset($folder['Snippets']) == true)
{
foreach ($folder['Snippets'] as $snippets)
{
$dir = implode('/', $depth);
$dir = ($dir != '') ? $dir . '/' : '';
if (isset($snippets['Contents1']) == true)
{
echo 'Exporting: ', $dir, '<br />';
mkdir($dir, 0777, true);
file_put_contents($dir . $snippets['Title'] . $ext, $snippets['Contents1']);
}
else
{
echo 'Exporting: ', $dir, '<br />';
mkdir($dir, 0777, true);
foreach ($snippets as $snippet)
{
file_put_contents($dir . $snippet['Title'] . $ext, $snippet['Contents1']);
}
}
}
}
if (isset($folder['SubFolders']) == true)
{
parseLibrary($folder['SubFolders'], $depth);
}
array_pop($depth);
}
}
// Wohoo!
parseLibrary($arrayData['Folder'], array());
echo 'Ready!';
?>
Nikolay Dutchuk
Blumentals Software
Blumentals Software
-
- Posts: 9
- Joined: Thu Oct 07, 2010 10:14 pm
Re: Export webuilder snippets to folder and textfile structu
Hello Nikolajs,
Thank you very very much for your example.
But it doesn't work 100% when I test it.
The main categories (I call them "main folders") are beeing put whitin each other
Example, we have the following main categories (main folders)
Your code works but exports it this way
The main folder "HTML" gets placed within "PHP" and the main folder "CSS" gets placed whitin "HTML"
I simplified the XML you could test it on this simplified XML file.
If you have the time and chance, could you change the code slightly?
Thank you very much!
Thank you very very much for your example.
But it doesn't work 100% when I test it.
The main categories (I call them "main folders") are beeing put whitin each other
Example, we have the following main categories (main folders)
Code: Select all
PHP
|
HTML
|
CSS
Code: Select all
PHP
|
----HTML
|
|------CSS
I simplified the XML you could test it on this simplified XML file.
Code: Select all
<?xml version = "1.0"?>
<Folder-list>
<Folder>
<Expanded>False1a</Expanded>
<Snippets></Snippets>
<SubFolders>
<Folder>
<Expanded>False1b</Expanded>
<Snippets></Snippets>
<SubFolders>
<Folder>
<Expanded>False1c</Expanded>
<Snippets>
<Snippet>
<CallWord></CallWord>
<Contents1>contents of sub-sub-1</Contents1>
<Contents2></Contents2>
<ShCut>0</ShCut>
<Title>snippet-title-1</Title>
</Snippet>
</Snippets>
<SubFolders></SubFolders>
<Title>sub-sub-1</Title>
</Folder>
</SubFolders>
<Title>sub1</Title>
</Folder>
</SubFolders>
<zbc>1</zbc>
<Title>mainfolder-1</Title>
</Folder>
<Folder>
<Expanded>true2a</Expanded>
<Snippets></Snippets>
<SubFolders>
<Folder>
<Expanded>true2b</Expanded>
<Snippets></Snippets>
<SubFolders>
<Folder>
<Expanded>true2c</Expanded>
<Snippets>
<Snippet>
<CallWord></CallWord>
<Contents1>contents of sub-sub-2</Contents1>
<Contents2></Contents2>
<ShCut>0</ShCut>
<Title>snippet-title-2</Title>
</Snippet>
</Snippets>
<SubFolders></SubFolders>
<Title>sub-sub-2</Title>
</Folder>
</SubFolders>
<Title>sub2</Title>
</Folder>
</SubFolders>
<zbc>2</zbc>
<Title>mainfolder-2</Title>
</Folder>
</Folder-list>
Thank you very much!
Re: Export webuilder snippets to folder and textfile structu
Yes, I have forgot to add a line to maintain folder structure. See updated code.
Nikolay Dutchuk
Blumentals Software
Blumentals Software
-
- Posts: 9
- Joined: Thu Oct 07, 2010 10:14 pm
Re: Export webuilder snippets to folder and textfile structu
THANK YOU Nikolajs !!!
Re: Export webuilder snippets to folder and textfile structu
Thanks for this great script!
I experienced two issues, though:
1st:
Support for german umlauts!
Umlauts get "destroyed" after export.
2nd:
Only the snippet parts "before cursor" are exportet in the txt-files. The "after cursor" part is missing!
Maybe you can fix that?
I experienced two issues, though:
1st:
Support for german umlauts!
Umlauts get "destroyed" after export.
2nd:
Only the snippet parts "before cursor" are exportet in the txt-files. The "after cursor" part is missing!
Maybe you can fix that?
Re: Export webuilder snippets to folder and textfile structu
Here's a fix for my suggestions:
Code: Select all
<?php
$rawContent = file_get_contents('library.xml');
$xmlContent = simplexml_load_string($rawContent);
// Quick & dirty way to convert XML to array
$jsonData = json_encode($xmlContent);
$arrayData = json_decode($jsonData, true);
// Our Library parse function.
function parseLibrary(array $array, array $depth)
{
$ext = '.txt';
foreach ($array as $folder)
{
if (isset($folder['Title']) == true) $depth[] = $folder['Title'];
if (isset($folder['Snippets']) == true)
{
foreach ($folder['Snippets'] as $snippets)
{
$dir = implode('/', $depth);
$dir = ($dir != '') ? $dir . '/' : '';
if (isset($snippets['Contents1']) == true)
{
echo 'Exporting: ', $dir, '<br />';
mkdir($dir, 0777, true);
$text = $snippets['Contents1'];
if (isset($snippets['Contents2']) && is_string($snippet['Contents2'])) {
$text .= $snippets['Contents2'];
}
file_put_contents($dir . str_replace (':', '', utf8_decode($snippets['Title'])) . $ext, $text);
}
else
{
echo 'Exporting: ', $dir, '<br />';
mkdir($dir, 0777, true);
foreach ($snippets as $snippet) {
$text = $snippet['Contents1'];
if (isset($snippet['Contents2']) && is_string($snippet['Contents2'])) {
$text .= $snippet['Contents2'];
}
file_put_contents($dir . str_replace (':', '', utf8_decode($snippet['Title'])) . $ext, $text);
}
}
}
}
if (isset($folder['SubFolders']) == true)
{
parseLibrary($folder['SubFolders'], $depth);
}
array_pop($depth);
}
}
parseLibrary($arrayData['Folder'], array());
echo 'Ready!';
?>
Re: Export webuilder snippets to folder and textfile structu
That part is missing because it was intially not needed. It should not be hard to modify the script to fit a specific need.
Nikolay Dutchuk
Blumentals Software
Blumentals Software