\n" . str_replace(array("\n", " "), array('
', ' '), htmlspecialchars($app_output)) . "\n";
else
return str_replace(array("\n", " "), array('
', ' '), htmlspecialchars($app_output));
}
return $app_output;
}
function app_has_output()
{
global $app_output;
return strlen(trim($app_output)) > 0;
}
function app_has_error()
{
global $app_error;
if(!is_array($app_error))
return false;
if(key($app_error) !== null)
return true;
else
{
@reset($app_error);
return false;
}
}
function app_get_error()
{
global $app_error;
$e = (object)current($app_error);
next($app_error);
return $e;
}
function app_check_update()
{
if($_GET['update'] == 1)
return true;
return false;
}
function app_check_settings()
{
if($_GET['settings'] == 1 || isset($_POST['app_settings']))
return true;
return false;
}
/**
* Mod Functions
*/
function app_get_mods()
{
global $app_mods;
$mods = array();
$dir = './mods';
foreach(new DirectoryIterator($dir) as $info)
{
if($info->isDir() && !$info->isDot())
{
$fname = str_replace('.php', '', $info->getFilename());
if(file_exists($dir . '/' . $fname . '/' . $fname . '.php'))
{
$mods[] = $fname;
if(isset($app_mods[$fname]))
$app_mods[$fname]['include'] = $dir . '/' . $fname . '/' . $fname . '.php';
else
{
$app_mods[$fname] = array();
$app_mods[$fname]['status'] = 'ready';
$app_mods[$fname]['include'] = $dir . '/' . $fname . '/' . $fname . '.php';
}
}
}
elseif($info->isFile())
{
$mods[] = $fname;
if(isset($app_mods[$fname]))
$app_mods[$fname]['include'] = $dir . '/' . $fname . '.php';
else
{
$app_mods[$fname] = array();
$app_mods[$fname]['status'] = 'ready';
$app_mods[$fname]['include'] = $dir . '/' . $fname . '.php';
}
}
}
return $mods;
}
function mod_activate($mod)
{
}
/*
function app_register_mod($name, $file)
{
global $app_mods;
if($app_mods[$name])
return;
$mod = array('name' => $name,
'file' => $file,
'status' => 'ready');
}
*/
function app_mod_install($name)
{
global $app_warnings;
global $app_mods;
if(!$app_mods[$name])
{
$app_warnings[] = 'Cannot install mod: ' . $name . ' is not available';
return;
}
require_once('mods/' . $app_mods[$name]['file']);
}
/**
* Core Functions
*/
/**
* Syntax Highlighting Functions
*/
//returns an associative array containing each line of code, line number, and error info
function app_highlight($source_code)
{
if (is_array($source_code))
return false;
$source_code = explode("\n", str_replace(array("\r\n", "\r"), "\n", $source_code));
$line_count = 1;
$source = array();
foreach ($source_code as $code_line)
{
$err = ''; //place holder
$errMsg = '';
global $app_error;
$c = count($app_error);
$errExists = false;
for($i = 0; ($i < $c) && !$errExists; $i++)
{
if($app_error[$i]['line'] == $line_count)
{
$err = $app_error[$i]['type'];
$errMsg = $app_error[$i]['message'];
$errExists = true;
}
}
if (preg_match('/<\?(php)?[^[:graph:]]/', $code_line) || $code_line == '', ''), '', app_highlight_string($code_line));
else
$formatted_code = preg_replace('/(<\?php )+/', '', str_replace(array('', ''), '', app_highlight_string($code_line, ' $line_count,
'code' => $formatted_code,
'error' => $err,
'error_msg' => $errMsg);
$line_count++;
}
return $source;
}
//helper function
//addresses comment bug in above function
function app_highlight_string($code, $append = '')
{
global $comment_toggle;
$out;
if($comment_toggle)
$out = str_replace('/*[temp]', '', highlight_string($append . '/*[temp]' . $code, true));
else
$out = highlight_string($append . $code, true);
if(strstr($code, '/*'))
$comment_toggle = true;
if(strstr($code, '*/'))
$comment_toggle = false;
return $out;
}
/**
* Page Element Functions
*/
$GLOBALS['app_elements'] = array();
function app_register_element($file)
{
$args = array();
$callback = '';
if(func_num_args() > 1)
{
$args = func_get_args();
array_shift($args); //remove $file
//array_shift($args); //remove $position
$callback = array_shift($args);
}
$GLOBALS['app_elements'][] = array('file' => $file,
'callback' => $callback,
'args' => $args);
}
function app_get_elements()
{
$app_elements = $GLOBALS['app_elements'];
return $app_elements;
}
/**
* Setting functions
*/
function app_register_setting($name, $label, $type, $default = null, $options = null, $group = null)
{
global $app_settings;
$form_group = ($group) ? $group : 'main';
$app_settings['template_settings'][$group][$name] = array('label' => $label, 'type' => $type, 'default' => $default, 'options' => $options);
}
function app_get_form_settings($group = null)
{
return ($group) ? $app_settings['template_settings'][$group] : $app_settings['template_settings'];
}
function app_settings_draw($excludes = null)
{
global $app_settings;
$groups = array();
if($excludes && is_array($excludes))
{
foreach($app_settings['template_settings'] as $group => $elements)
{
if(!in_array($group, $excludes))
{
$groups[$group] = $elements;
}
}
}
else
{
$groups = $app_settings['template_settings'];
}
$names = array();
ob_start();
foreach($groups as $group => $elements) : ?>