<?php
class FSHelper
{
protected static $deniedOptions = array
( 'showFromDate'
, 'showToDate'
, 'textToken'
, 'type'
, 'location'
);
public static function getFilesystemElements($path)
{
echo '<ul>';
foreach($GLOBALS['filesystem']->getList($path /*, XMLFS::INCLUDE_INVISIBLES*/) as $file)
{
$conformpath = preg_replace('/\/$/', '', $path).'/'.$file->getAttribute('name').'/';
if($file->getAttribute('redirect'))
$conformpath = $file->getAttribute('redirect');
$class = trim(($file->getAttribute('redirect') ? 'redirect ':'').($file->getAttribute('invisible') == '1' ? 'invisible ':''));
echo '<li>';
echo '<a href="?file='.$conformpath.'" class="'.$class.'">'
.(isset($_GET['file']) && $_GET['file'] == $conformpath ? '<strong>' : '')
.$file->getAttribute('name').($file->getAttribute('redirect') ? ' (redirect to: "'.$file->getAttribute('redirect').'")':'')
.(isset($_GET['file']) && $_GET['file'] == $conformpath ? '</strong>' : '')
.'</a>'
.'<a href="?deletefile='.$conformpath.'" class="deletefile" title="Delete file">x</a>';
if($GLOBALS['filesystem']->hasChildren($path.$file->getAttribute('name')/*, XMLFS::INCLUDE_INVISIBLES*/))
self::getFilesystemElements($path.$file->getAttribute('name').'/');
echo '</li>';
}
echo '</ul>'.PHP_EOL;
}
public static function createControl(WritableXMLFSControl $control)
{
?>
<ul class="controls">
<li>
<div class="boxed control<?php echo ($control->getName() === '#text' ? ' continuous' : '');?>" xpath="<?php echo $control->createXpath() ?>" name="<?php echo $control->getName();?>" file="<?php echo (isset($_POST['file']) ? $_POST['file'] : $_GET['file']) ?>">
<?php
if(count($control->availableSubControls()) > 0)
{
?>
<div class="addControl">
<span>
new:
<select name="addControl">
<option selected="selected" value="">- select -</option>
<?php
foreach($control->availableSubControls() as $subControl)
{
?>
<option value="<?php echo $subControl ?>"><?php echo $subControl ?></option>
<?php
}
?>
</select>
<span class="method"><span class="boxed" name="before" title="insert new element before current">before</span><span class="boxed" selected="selected" name="append" title="insert new element inside current">inside</span><span class="boxed" name="after" title="insert new element after current">after</span></span>
</span>
<!---->
</div>
<?php
}
echo '<strong class="title">';
if($control->getName() != '#text')
echo $control->getName();
echo ' ';
if($control->canDelete())
echo '<a href="#" class="boxed delete" title="Delete this control">−</a>';
echo '</strong>';
if($control->getName() === '#text')
{
?><table><tr><td class="boxed option continuous"><span><input type="text" name="continuoustext" placeholder="continuous text..." value="<?php echo $control->getNode()->nodeValue ?>"/></span></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<?php
}
elseif(count(array_diff($control->getOptions(), self::$deniedOptions)) > 0)
{
echo '<table>';
$i = 0;
foreach($control->getOptions() as $optionName)
if(!in_array($optionName, self::$deniedOptions))
{
$defaultOption = $control->getDefaultOption($optionName);
$placeholder = $defaultOption ? 'default: '.$defaultOption : '';
echo ($i % 4 == 0 ? '<tr>' : '');
?>
<td class="boxed option" title="<?php echo $optionName?>">
<span class="description"><?php echo $optionName?></span>
<span class="value"><input type="text" name="<?php echo $optionName?>" placeholder="<?php echo $placeholder?>" value="<?php echo ($control->getOption($optionName) != $control->getDefaultOption($optionName) ? $control->getOption($optionName) : '')?>"/></span>
</td>
<?php
echo (++$i % 4 == 0 ? '</tr>'.PHP_EOL : '');
}
for($i; ($i % 4) != 0; $i++)
{
echo '<td> </td>';
if((($i + 1) % 4) == 0)
echo '</tr>'.PHP_EOL;
}
echo '</table>';
}
?>
</table>
</div>
<?php
foreach($control->subControls() as $subControl)
self::createControl($subControl);
?>
</li>
</ul>
<?php
}
}