Esempio n. 1
0
 function BoxchooserSettingsForm()
 {
     parent::MailForm();
     page_title(intl_get('Box Settings'));
     //set(array('title'=>'Add a Box'));
     global $cgi;
     //set
     if (!$cgi->box) {
         echo 'Missing parameter: box';
         exit;
     }
     ini_add_filter('ini_filter_split_comma_single', array('rule 0', 'rule 1', 'rule 2', 'rule 3', 'rule 4', 'rule 5', 'rule 6', 'rule 7', 'rule 8', 'button 0', 'button 1', 'button 2', 'button 3', 'button 4', 'button 5', 'button 6', 'button 7', 'button 8'));
     $this->_box_settings = ini_parse('inc/app/' . $cgi->app . '/boxes/' . $cgi->box . '/settings.php');
     ini_clear();
     unset($this->_box_settings['Meta']);
     if (count($this->_box_settings) === 0) {
         $this->onSubmit((array) $cgi);
         return;
     }
     foreach ($this->_box_settings as $k => $v) {
         $this->createWidget($k, $v);
     }
     $this->addWidget('hidden', 'app');
     $this->addWidget('hidden', 'box');
     $this->addWidget('hidden', 'name');
     $w =& $this->addWidget('submit', 'sub');
     $w->setValues(intl_get('Done'));
 }
Esempio n. 2
0
 function SitetemplateEditsetForm()
 {
     parent::MailForm();
     global $cgi;
     $set = $cgi->set;
     $this->parseSettings('inc/app/sitetemplate/forms/editset/settings.php');
     $settings = array();
     if (file_exists('inc/html/' . $set . '/config.ini.php')) {
         $settings = ini_parse('inc/html/' . $set . '/config.ini.php', false);
     }
     $name = $settings['set_name'];
     if (!$name) {
         $name = $set;
     }
     $settings['set'] = $set;
     //put form values into respective forms
     foreach ($settings as $k => $v) {
         $this->widgets[$k]->setDefault($v);
     }
     if (@file_exists('inc/html/' . $set . '/modes.php')) {
         $this->widgets['modes']->setDefault(@join('', @file('inc/html/' . $set . '/modes.php')));
     } else {
         $this->widgets['modes']->setDefault($modesd);
     }
     $this->widgets['submit_button']->buttons[1]->extra = 'onclick="history.go (-1); return false"';
     page_title(intl_get('Editing Properties') . ': ' . $name);
 }
Esempio n. 3
0
 function onSubmit($vals)
 {
     $file = $this->_file;
     $info = ini_parse($file);
     $code = $vals['code'];
     if (!empty($vals['locale'])) {
         $code .= '-' . $vals['locale'];
     }
     $info[$code] = array('name' => $vals['name'], 'code' => $vals['code'], 'locale' => $vals['locale'], 'charset' => $vals['charset'], 'fallback' => $vals['fallback'], 'default' => $vals['default']);
     $fp = fopen($file, 'w');
     if (!$fp) {
         echo 'Error: Failed to open languages.php file!';
         return;
     }
     fwrite($fp, ini_write($info));
     fclose($fp);
     /*header (
     			sprintf (
     				'Location: %s/index/appdoc-translation-strings-action?appname=%s&lang=%s&charset=%s',
     				site_prefix (),
     				$vals['appname'],
     				$code,
     				$vals['charset']
     			)
     		);*/
     header('Location: ' . site_prefix() . '/index/multilingual-languages-action');
     exit;
 }
Esempio n. 4
0
function sitesearch_filter_ctype($ctype)
{
    $info = ini_parse('inc/app/cms/conf/collections/' . $ctype . '.php');
    if (isset($info['Collection']['display'])) {
        return $info['Collection']['display'];
    }
    return $ctype;
}
Esempio n. 5
0
 function SitewikiSettingsForm()
 {
     parent::MailForm(__FILE__);
     $settings = ini_parse('inc/app/sitewiki/conf/settings.php', false);
     foreach ($settings as $k => $v) {
         $this->widgets[$k]->setValue($v);
     }
 }
Esempio n. 6
0
/**
 * Looks recursively through the directory structure for an access.php file.
 * If found, it will return this file parsed into an array.
 *
 * @param string
 * @param string
 * @return array
 *
 */
function help_get_access($path, $stop)
{
    if (@file_exists($path . '/access.php')) {
        return ini_parse($path . '/access.php', false);
    }
    $info = pathinfo($path);
    $newpath = $info['dirname'];
    if ($newpath == $stop) {
        return array();
    }
    return help_get_access($newpath, $stop);
}
Esempio n. 7
0
 function Rex($collection)
 {
     // gets collection definition from inc/app/cms/conf/collections
     $this->info = ini_parse('inc/app/cms/conf/collections/' . $collection . '.php');
     if (!is_array($this->info) || count($this->info) == 0) {
         $this->collection = false;
         return;
     }
     $this->collection = $this->info['Collection']['name'];
     $this->key = $this->info['Collection']['key_field'];
     $this->title = $this->info['Collection']['title_field'];
     $this->body = $this->info['Collection']['body_field'];
     $this->isVersioned = $this->info['Collection']['is_versioned'];
     $this->allowUppercaseKey = $this->info['Collection']['allow_uppercase_key'];
     foreach ($this->info as $key => $settings) {
         if (strpos($key, 'facet:') === 0) {
             $key = substr($key, 6);
             $this->addFacet($key, $settings);
             /*
             				$type = $settings['type'];
             				if (strpos ($type, '.') !== false) {
             					loader_import ($type);
             					$type = array_pop (explode ('.', $type));
             				}
             				$type = 'r' . ucfirst (strtolower ($type)) . 'Facet';
             				$this->facets[$key] = new $type ($key, $settings);
             				$this->facets[$key]->preserve = array ('collection', 'orderBy', 'sort');
             				if ($settings['fields']) {
             					$this->facets[$key]->fields = preg_split ('/, ?/', $settings['fields'], -1, PREG_SPLIT_NO_EMPTY);
             				}*/
         }
     }
     $this->rev = new Rev($this->info['Source']['name'], $this->info['Store']['name']);
     $this->rev->isVersioned = $this->isVersioned;
     $this->rev->allowUppercaseKey = $this->allowUppercaseKey;
     foreach ($this->info['Source'] as $k => $v) {
         if ($k == 'name') {
             continue;
         }
         $this->rev->source->{$k} = $v;
     }
     foreach ($this->info['Store'] as $k => $v) {
         if ($k == 'name') {
             continue;
         }
         $this->rev->store->{$k} = $v;
     }
 }
Esempio n. 8
0
    function UsradmSettingsForm()
    {
        parent::MailForm(__FILE__);
        page_add_style('
			td.label {
				width: 200px;
			}
			td.field {
				padding-left: 7px;
				padding-right: 7px;
			}
		');
        $config = ini_parse('inc/conf/config.ini.php');
        foreach ($config as $cname => $conf) {
            foreach ($conf as $k => $v) {
                if (isset($this->widgets[$cname . '_' . $k])) {
                    $this->widgets[$cname . '_' . $k]->setValue($v);
                }
            }
        }
    }
Esempio n. 9
0
 function onSubmit($vals)
 {
     // overwrite file
     $cache = array('Cache' => array(), 'Cacheable' => array());
     $cacheable = $vals['cacheable'];
     unset($vals['cacheable']);
     unset($vals['submit_button']);
     foreach ($vals as $k => $v) {
         $cache['Cache'][$k] = $v;
     }
     $cacheable = ini_parse($cacheable, false);
     foreach ($this->ignore as $i) {
         $cacheable[$i] = false;
     }
     $cache['Cacheable'] = $cacheable;
     loader_import('saf.File');
     if (!file_overwrite('inc/conf/cache.php', ini_write($cache))) {
         die('Error writing to file: inc/conf/cache.php');
     }
     echo '<p>' . intl_get('Cache settings saved.') . '  <a href="' . site_prefix() . '/index/cms-cpanel-action">' . intl_get('Continue') . '</a></p>';
 }
Esempio n. 10
0
<?php

// This is where app-level variables can be centrally stored.  This file is
// automatically included when the first call to your app is made.  Use the
// appconf_set ('name', 'value'); function to add values here.
$conf = ini_parse('inc/app/sitewiki/conf/settings.php', false);
foreach ($conf as $k => $v) {
    if ($k == 'template' && $context == 'action') {
        page_template($v);
    } else {
        appconf_set($k, $v);
    }
}
appconf_set('default_page', 'HomePage');
appconf_set('date_format', 'F j, Y g:i A');
appconf_set('levels', array('0' => intl_get('Anyone'), '1' => intl_get('Registered Users Only'), '2' => intl_get('Admin-Level Users Only'), '3' => intl_get('Owner Only')));
appconf_set('yesno', array('0' => intl_get('No'), '1' => intl_get('Yes')));
//page_template ('full');
page_add_link('alternate', 'application/rss+xml', site_url() . '/index/sitewiki-feeds-short-action');
page_add_link('alternate', 'application/rss+xml', site_url() . '/index/sitewiki-feeds-full-action');
Esempio n. 11
0
 function getFormSettings($name)
 {
     $app = $this->getApp($name);
     $name = $this->removeApp($name, $app);
     if (@file_exists($this->prefix . '/' . $app . '/' . $this->formPath . '/' . $name . '/settings.php')) {
         return ini_parse($this->prefix . '/' . $app . '/' . $this->formPath . '/' . $name . '/settings.php', true);
     }
     return array();
 }
Esempio n. 12
0
    $rules = array();
    foreach ($value as $k => $v) {
        if (strpos($k, 'rule ') === 0) {
            $rules[] = $v;
        }
    }
    if (count($rules) == 0) {
        $rules = false;
    }
    $data['params'][$key]['rules'] = $rules;
}
ob_start();
highlight_file($path . '/index.php');
$data['source'] = ob_get_contents();
ob_end_clean();
$info = ini_parse(getcwd() . '/inc/app/' . $parameters['appname'] . '/conf/config.ini.php', false);
$fullname = $info['app_name'];
if (!$fullname) {
    $fullname = ucfirst($parameters['appname']);
}
$pathinfo = explode('/', $parameters['form']);
foreach ($pathinfo as $key => $value) {
    $pathinfo[$key] = ucfirst($value);
}
if (!empty($data['info']['name'])) {
    $pathinfo[count($pathinfo) - 1] = $data['info']['name'];
}
$name = join(' / ', $pathinfo);
page_title(intl_get('AppDoc') . ': ' . $fullname . ' / ' . $name);
echo template_simple('<p><a href="{site/prefix}/index/appdoc-appinfo-action?appname={cgi/appname}">{intl Back}</a></p>');
echo template_simple('formviewer.spt', $data);
Esempio n. 13
0
 /**
  * Parses the specified file using the parse_ini_file()
  * function.  Sections in the file correspond to the names of
  * widgets you wish to create, in addition to a [Form] section
  * that sets properties for the form itself.  The values in
  * each section correspond to properties or methods of the
  * widgets.  This method can be used to simplify the process
  * of defining and customizing a form.
  * 
  * @access	public
  * @param	string	$file
  * @return	boolean
  * 
  */
 function parseSettings($file)
 {
     if (!@file_exists($file)) {
         return false;
     }
     ini_add_filter('ini_filter_split_comma_single', array('rule 0', 'rule 1', 'rule 2', 'rule 3', 'rule 4', 'rule 5', 'rule 6', 'rule 7', 'rule 8', 'button 0', 'button 1', 'button 2', 'button 3', 'button 4', 'button 5', 'button 6', 'button 7', 'button 8', 'submitButtons'));
     $conf = ini_parse($file, true);
     ini_clear();
     if (count($conf) == 0) {
         return false;
     }
     // form properties, optional
     if (is_array($conf['Form'])) {
         foreach ($conf['Form'] as $key => $value) {
             if (($key == 'title' || $key == 'message') && function_exists('intl_get')) {
                 $value = intl_get($value);
             }
             $this->{$key} = $value;
         }
         unset($conf['Form']);
     }
     foreach ($conf as $name => $data) {
         $this->createWidget($name, $data);
     }
     return true;
 }
Esempio n. 14
0
 /**
  * Determines whether the specified service is active.
  *
  * @access public
  * @param string
  * @param array
  * @return boolean
  *
  */
 function active($service, $actions)
 {
     foreach ($actions as $action) {
         $c = ini_parse('inc/app/cms/conf/services/' . $action . '.php');
         if (isset($c['service:' . $service])) {
             return true;
         }
     }
     return false;
 }
Esempio n. 15
0
}
if (!isset($cgi->offset)) {
    if (isset($cgi->osoffset)) {
        $cgi->offset = ($cgi->osoffset - 1) * $cgi->limit;
    } else {
        $cgi->offset = 0;
    }
}
$settings = @parse_ini_file('inc/app/sitesearch/conf/server.ini.php');
$sitesearch_allowed = array();
loader_import('saf.File.Directory');
foreach (Dir::fetch('inc/app/cms/conf/collections') as $file) {
    if (strpos($file, '.') === 0 || @is_dir('inc/app/cms/conf/collections/' . $file)) {
        continue;
    }
    $config = ini_parse('inc/app/cms/conf/collections/' . $file);
    if (isset($config['Collection']['sitesearch_url'])) {
        if (isset($config['Collection']['sitesearch_access']) && session_allowed($config['Collection']['sitesearch_access'], 'r', 'access')) {
            $sitesearch_allowed[] = $config['Collection']['name'];
        }
    }
}
if (!empty($parameters['query'])) {
    loader_import('sitesearch.SiteSearch');
    $searcher = new SiteSearch();
    if (is_array($parameters['ctype'])) {
        $collections = $parameters['ctype'];
        foreach ($collections as $k => $ctype) {
            if (!in_array($ctype, $sitesearch_allowed)) {
                unset($collections[$k]);
            }
Esempio n. 16
0
if (isset($info['app_name'])) {
    $name = $info['app_name'];
} else {
    $name = ucfirst($file);
}
page_title(intl_get('Application Settings') . ' - ' . $name);
if (!is_writeable(getcwd() . '/inc/app/' . $parameters['appname'] . '/conf/settings.ini.php')) {
    echo '<p class="invalid">' . intl_getf('Warning: The settings file is not writeable. Please verify that the file %s is writeable by the web server user.', 'inc/app/' . $parameters['appname'] . '/conf/settings.ini.php') . '</p>';
    return;
}
global $intl;
$old_intl_path = $intl->directory;
$intl->directory = 'inc/app/' . $parameters['appname'] . '/lang';
$intl->getIndex();
$intl->directory = $old_intl_path;
$settings = ini_parse(getcwd() . '/inc/app/' . $parameters['appname'] . '/conf/settings.ini.php', true);
global $cgi;
loader_import('saf.MailForm');
$form = new MailForm();
$w =& $form->addWidget('hidden', 'appname');
$w->setValue($parameters['appname']);
foreach ($settings as $k => $v) {
    if (!isset($v['type'])) {
        $v['type'] = 'text';
    }
    if (isset($v['value'])) {
        $val = $v['value'];
        unset($v['value']);
    } else {
        $val = false;
    }
Esempio n. 17
0
    $attrs = array_merge($attrs, $defaults);
}
$css = new CSS_Parser();
$classes = array();
$ids = array();
foreach (Dir::find('*.css', 'inc/html/' . conf('Server', 'default_template_set')) as $file) {
    $css->parse(@join('', @file($file)));
    $classes = array_merge($classes, $css->getClasses($cgi->tag));
    $ids = array_merge($ids, $css->getIDs($cgi->tag));
}
$classes = array_unique($classes);
$ids = array_unique($ids);
$form = new MailForm();
ini_add_filter('ini_filter_split_comma_single', array('rule 0', 'rule 1', 'rule 2', 'rule 3', 'rule 4', 'rule 5', 'rule 6', 'rule 7', 'rule 8', 'button 0', 'button 1', 'button 2', 'button 3', 'button 4', 'button 5', 'button 6', 'button 7', 'button 8', 'submitButtons'));
foreach ($attrs as $attr) {
    $w =& $form->createWidget($attr->name, ini_parse($attr->typedef, false));
    if (isset($cgi->{$attr->name})) {
        $w->setDefault($cgi->{$attr->name});
    }
}
ini_clear();
if (isset($form->widgets['id'])) {
    $form->widgets['id']->setValues(array_merge(array('' => '- ' . intl_get('SELECT') . ' -'), assocify($ids)));
}
if (isset($form->widgets['class'])) {
    $form->widgets['class']->setValues(array_merge(array('' => '- ' . intl_get('SELECT') . ' -'), assocify($classes)));
}
$w =& $form->addWidget('hidden', 'ifname');
$w->setValue($cgi->ifname);
$w =& $form->addWidget('hidden', 'tag');
$w->setValue($cgi->tag);
Esempio n. 18
0
<?php

global $cgi;
$data = array();
$content_types = array();
$GLOBALS['_content_weights'] = array();
$applications = parse_ini_file('inc/conf/auth/applications/index.php');
loader_import('saf.File.Directory');
$files = Dir::find('*.php', 'inc/app/cms/conf/collections', false);
foreach ($files as $file) {
    if (strstr($file, '/.')) {
        continue;
    }
    $data = ini_parse($file);
    $GLOBALS['_content_weights'][$data['Collection']['name']] = $data['Collection']['list_weight'];
    if (!isset($data['Collection']['visible']) || $data['Collection']['visible'] != false) {
        if (session_is_resource($data['Collection']['name']) && !session_allowed($data['Collection']['name'], 'rw', 'resource')) {
            continue;
        }
        if (isset($data['Collection']['app']) && isset($applications[$data['Collection']['app']]) && !$applications[$data['Collection']['app']]) {
            continue;
        }
        $content_types[$data['Collection']['name']] = intl_get($data['Collection']['display']);
    }
}
function cms_collection_sort($a, $b)
{
    global $_content_weights, $_content_types;
    if ($a == $b) {
        return 0;
    }
Esempio n. 19
0
<?php

global $cgi;
if (empty($cgi->appname) || strstr($cgi->appname, '..') || !@is_dir('inc/app/' . $cgi->appname)) {
    header('Location: ' . site_prefix() . '/index/appdoc-app');
    exit;
}
if (empty($cgi->lang)) {
    $cgi->lang = 'en';
}
$info = ini_parse(getcwd() . '/inc/app/' . $cgi->appname . '/conf/config.ini.php', false);
page_title(intl_get('Help Files') . ': ' . $info['app_name']);
if (!@is_dir('inc/app/' . $cgi->appname . '/docs/' . $cgi->lang)) {
    loader_import('saf.File.Directory');
    $res = Dir::build('inc/app/' . $cgi->appname . '/docs/' . $cgi->lang, 0777);
    if (!$res) {
        echo '<p>' . intl_get('Failed to create directory') . ': docs/' . $cgi->lang . '</p>';
        echo '<p><a href="javascript: history.go (-1)">' . intl_get('Back') . '</a></p>';
        return;
    }
}
loader_import('help.Help');
$data = array('appname' => $cgi->appname, 'lang' => $cgi->lang, 'files' => array(), 'langs' => help_get_langs($cgi->appname));
$files = help_get_pages($cgi->appname, $cgi->lang);
if (!is_array($files)) {
    $files = array();
}
foreach ($files as $file) {
    $id = help_get_id($file);
    $body = @join('', @file($file));
    $word_count = count(preg_split('/\\W+/s', strip_tags($body), -1, PREG_SPLIT_NO_EMPTY));
Esempio n. 20
0
    function display($generate_html = 0)
    {
        parent::display($generate_html);
        global $intl, $simple, $cgi;
        // needs browser check to display textarea as alternative
        $this->initial_value = $this->formatValue($this->data_value);
        $this->scroller_data = $this->formatValue($this->scroller_data);
        if ($this->reference !== false) {
            if (empty($this->reference)) {
                $this->reference = '<br />';
            }
            $this->reference = $this->formatValue($this->reference);
        }
        loader_import('ext.phpsniff');
        $ua = new phpSniff();
        if ($ua->property('browser') == 'ie' && $ua->property('platform') == 'win' && $ua->property('version') >= '5.5' || $ua->property('browser') == 'mz' && $ua->property('version') >= '1.3' || $ua->property('browser') == 'ns' && $ua->property('version') >= '5.0' || $ua->property('browser') == 'fb' && $ua->property('version') >= '0.7' || $ua->property('browser') == 'ca' && $ua->property('version') >= '1.0' || $ua->property('browser') == 'sf' && $ua->property('version') >= '522' || strpos($ua->property('ua'), 'adobeair')) {
            // go xed
            if ($ua->property('browser') == 'ie') {
                $this->msie = true;
                if ($ua->property('version') >= '7.0') {
                    $this->msie7 = 'true';
                }
            }
            if ($ua->property('browser') == 'sf') {
                $this->safari = 'true';
            } elseif (strpos($ua->property('ua'), 'adobeair')) {
                $this->safari = 'true';
                $this->adobeair = 'true';
            }
            if (@file_exists('inc/html/' . conf('Server', 'default_template_set') . '/images.php')) {
                if ($cgi->_collection) {
                    $collection = $cgi->_collection;
                } elseif ($cgi->collection) {
                    $collection = $cgi->collection;
                } else {
                    $collection = false;
                }
                if ($collection) {
                    $images = ini_parse('inc/html/' . conf('Server', 'default_template_set') . '/images.php');
                    if (isset($images[$collection])) {
                        $this->max_height = $images[$collection]['max_height'];
                        $this->max_width = $images[$collection]['max_width'];
                        if ($images[$collection]['popup']) {
                            $this->img_popup = 'true';
                        } else {
                            $this->img_popup = 'false';
                        }
                    } else {
                        $this->max_height = 'false';
                        $this->max_width = 'false';
                        $this->img_popup = 'false';
                    }
                } else {
                    $this->max_height = 'false';
                    $this->max_width = 'false';
                    $this->img_popup = 'false';
                }
            } else {
                $this->max_height = 'false';
                $this->max_width = 'false';
                $this->img_popup = 'false';
            }
            // initialize modal dialog event handlers
            page_onload('xed_init (\'' . $this->name . '\')');
            page_onclick('checkModal ()');
            page_onfocus('return checkModal ()');
            template_bind('/html/body', '	<form style="display: inline" id="xed-' . $this->name . '-fsform" method="post" action="' . site_prefix() . '/index/xed-fullscreen-form" target="xedFullscreenWindow">
		<input type="hidden" name="ifname" value="' . $this->name . '" />
		<input type="hidden" name="xeditor" value="" />
	</form>');
            $this->templates = db_fetch_array('select * from xed_templates');
            foreach ($this->templates as $k => $t) {
                $this->templates[$k]->body = $this->formatValue($t->body);
            }
            $this->source_height = $this->height + 2;
            loader_import('saf.GUI.Prompt');
            $template = join('', file('inc/app/xed/html/xed.spt'));
            return template_simple($template, $this);
        } else {
            // return a textarea
            return '<tr><td class="field" colspan="2"><textarea name="' . $this->name . '" cols="50" rows="10">' . htmlentities_compat($this->data_value, ENT_COMPAT, $intl->charset) . '</textarea></td></tr>';
        }
    }
Esempio n. 21
0
 * This example simply lists all of the boxes and forms in the example app.
 */
loader_import('saf.File.Directory');
// get list of boxes
$d = new Dir('inc/app/example/boxes');
$boxes = array();
foreach ($d->readAll() as $file) {
    if (strpos($file, '.') === 0 || !@is_dir('inc/app/example/boxes/' . $file) || $file == 'CVS') {
        continue;
    }
    $box = array('file' => $file);
    if (@file_exists('inc/app/example/html/' . $file . '.spt')) {
        $box['template'] = true;
    }
    if (@file_exists('inc/app/example/boxes/' . $file . '/settings.php')) {
        $settings = @ini_parse('inc/app/example/boxes/' . $file . '/settings.php');
        $box['name'] = $settings['Meta']['name'];
    } else {
        $box['name'] = $file;
    }
    $boxes[] = $box;
}
// get list of forms
$d = new Dir('inc/app/example/forms');
$forms = array();
foreach ($d->read_all() as $file) {
    if (strpos($file, '.') === 0 || !@is_dir('inc/app/example/forms/' . $file) || $file == 'CVS') {
        continue;
    }
    $form = array('file' => $file);
    if (@file_exists('inc/app/example/html/' . $file . '.spt')) {
Esempio n. 22
0
<?php

exit;
global $cgi;
if ($cgi->appname == 'GLOBAL') {
    $file = 'inc/lang/languages.php';
    $path = 'inc/lang';
} else {
    $file = 'inc/app/' . $cgi->appname . '/lang/languages.php';
    $path = 'inc/app/' . $cgi->appname . '/lang';
}
$info = ini_parse($file);
foreach ($cgi->_key as $k) {
    unset($info[$k]);
}
$fp = fopen($file, 'w');
if (!$fp) {
    page_title('An Error Occurred');
    echo 'Error: Failed to open languages.php file!';
    return;
}
fwrite($fp, ini_write($info));
fclose($fp);
foreach ($cgi->_key as $k) {
    if (@file_exists($path . '/' . $k . '.php')) {
        unlink($path . '/' . $k . '.php');
    }
}
header('Location: ' . site_prefix() . '/index/appdoc-translation-action?appname=' . $cgi->appname);
exit;
Esempio n. 23
0
    if (strstr($cgi->lang, '-')) {
        list($code, $locale) = split('-', $cgi->lang);
    } else {
        $code = $cgi->lang;
        $locale = '';
    }
    // rewrite file
    global $intl;
    if (!$intl->writeLanguage($file_lang, $this->lang_hash[$cgi->lang], $code, $locale)) {
        page_title(intl_get('An Error Occurred'));
        echo $intl->error;
        return;
    }
}
if ($parameters['home'] == 'yes') {
    header('Location: ' . site_prefix() . '/index/multilingual-translation-action?appname=' . $cgi->appname);
    exit;
}
$parameters['screen_total'] = ceil(count($index) / $limit);
$parameters['screen_num'] = $cgi->offset / $limit + 1;
$parameters['more'] = $cgi->offset + $limit < count($index) ? true : false;
$show = array_slice($index, $cgi->offset, $limit);
foreach ($show as $k => $v) {
    $show[$k]['current'] = $this->lang_hash[$cgi->lang][stripslashes($k)];
}
header('Content-Type: text/html; charset=' . $cgi->charset);
$langs = ini_parse($file_langs);
page_title(intl_get('Editing Language') . ': ' . $langs[$cgi->lang]['name']);
template_simple_register('show', $show);
echo template_simple('translation_strings.spt', $parameters);
//info ($show, true);
Esempio n. 24
0
 function getList($collection, $key, $conditions, $limit, $offset, $orderBy, $sort, $count)
 {
     global $db;
     if ($count) {
         $sql = 'select count(*) as total from ' . $collection;
     } else {
         $sql = 'select ' . $key . ' from ' . $collection;
     }
     $bind = array();
     if (is_array($conditions) && count($conditions) > 0) {
         $sql .= ' where ' . NEWLINE;
         $op = '';
         foreach ($conditions as $condition) {
             switch (strtolower(get_class($condition))) {
                 case 'requal':
                     $sql .= $op . $condition->field . ' = ?' . NEWLINE;
                     $bind[] = $condition->value;
                     break;
                 case 'rnull':
                     $sql .= $op . $condition->field . ' is null' . NEWLINE;
                     break;
                 case 'rlike':
                     $sql .= $op . '(';
                     $old = $op;
                     $op = '';
                     foreach ($condition->getFields() as $field) {
                         if (empty($field)) {
                             continue;
                         }
                         $sql .= $op . $field . ' like ?' . NEWLINE;
                         $bind[] = $condition->value;
                         $op = ' or ';
                     }
                     $op = $old;
                     $sql .= ') ';
                     break;
                 case 'rregex':
                     $sql .= $op . $condition->field . ' regexp ?' . NEWLINE;
                     $bind[] = $condition->value;
                     break;
                 case 'rallowed':
                     $sql .= $op . $condition->allowed();
                     break;
                 case 'rlist':
                     $sql .= $op . $condition->field . ' in (';
                     $tmp = '';
                     foreach ($condition->getList() as $value) {
                         $sql .= $tmp . '?';
                         $bind[] = $value;
                         $tmp = ', ';
                     }
                     $sql .= ')' . NEWLINE;
                     break;
                 case 'rdaterange':
                     $sql .= $op . '(unix_timestamp(?) <= unix_timestamp(' . $condition->field . ') and unix_timestamp(?) >= unix_timestamp(' . $condition->field . '))' . NEWLINE;
                     $bind[] = $condition->from;
                     $bind[] = $condition->to;
                     break;
                 case 'rrange':
                     $sql .= $op . '(? <= ' . $condition->field . ' and ? >= ' . $condition->field . ')' . NEWLINE;
                     $bind[] = $condition->from;
                     $bind[] = $condition->to;
                     break;
                 case 'rliteral':
                     $sql .= $op . $condition->expr . NEWLINE;
                     break;
                 case 'rsitesearch':
                     $info = ini_parse('inc/app/cms/conf/collections/' . $collection . '.php');
                     if (!isset($info['Collection']['sitesearch_url'])) {
                         break;
                     }
                     if (!loader_import('sitesearch.SiteSearch')) {
                         break;
                     }
                     $searcher = new SiteSearch();
                     $res = @$searcher->query($condition->search, 100, 0, array($collection));
                     if (!$res || !is_array($res)) {
                         break;
                     }
                     $ids = array();
                     foreach (array_keys($res['rows']) as $k) {
                         $ids[] = array_shift(sscanf($res['rows'][$k]['url'], '/index/' . $info['Collection']['sitesearch_url']));
                     }
                     $sql .= $op . $key . ' in("' . join('","', $ids) . '")' . NEWLINE;
                     break;
             }
             $op = ' and ';
         }
     }
     if ($orderBy) {
         $sql .= ' order by ' . $orderBy;
         if ($sort) {
             $sql .= ' ' . $sort;
         }
     }
     /*
     		echo '<pre>';
     		echo $sql . NEWLINEx2;
     		print_r ($bind);
     		echo '</pre>';
     		//exit;
     */
     //		info ($sql);
     //		info ($bind, true);
     $q = $db->query($sql);
     if ($q->execute($bind)) {
         if ($count) {
             $res = $q->fetch();
             $this->total = $res->total;
             $q->free();
             return $res->total;
         }
         $this->total = $q->rows();
         if ($limit > 0) {
             $list = $q->fetch($offset, $limit);
         } else {
             $list = array();
             while ($row = $q->fetch()) {
                 $list[] = $row;
             }
         }
         $q->free();
         return $list;
     } else {
         $this->error = $q->error();
         return false;
     }
 }
Esempio n. 25
0
 function _settings($file, $data)
 {
     if (!@file_exists($file)) {
         return true;
     }
     ini_add_filter('ini_filter_split_comma_single', array('rule 0', 'rule 1', 'rule 2', 'rule 3', 'rule 4', 'rule 5', 'rule 6', 'rule 7', 'rule 8', 'button 0', 'button 1', 'button 2', 'button 3', 'button 4', 'button 5', 'button 6', 'button 7', 'button 8'));
     $data = ini_parse($file);
     ini_clear();
     if (!is_array($data)) {
         return true;
     }
     if (count($data) == 0) {
         return true;
     }
     foreach ($data as $section => $values) {
         foreach ($values as $k => $v) {
             if ($section == 'Form' && ($k == 'title' || $k == 'message')) {
                 $this->buffer->set($this->intl->serialize($v), array('string' => $v, 'params' => false, 'file' => $file, 'line' => false));
             } elseif ($k == 'alt' || $k == 'display_value' || $k == 'title') {
                 $this->buffer->set($this->intl->serialize($v), array('string' => $v, 'params' => false, 'file' => $file, 'line' => false));
             } elseif (strpos($k, 'rule ') === 0 && is_array($v)) {
                 $this->buffer->set($this->intl->serialize($v[1]), array('string' => $v[1], 'params' => false, 'file' => $file, 'line' => false));
             } elseif (strpos($k, 'button ') === 0) {
                 if (is_array($v)) {
                     $v = $v[0];
                 }
                 $this->buffer->set($this->intl->serialize($v), array('string' => $v, 'params' => false, 'file' => $file, 'line' => false));
             } elseif (strpos($v, 'eval:') === 0) {
                 $this->_php($file, OPEN_TAG . ' ' . substr($v, 5) . ' ' . CLOSE_TAG);
             }
         }
     }
     return true;
 }
Esempio n. 26
0
    /**
     * Loads a series of objects that are dynamically generated from an INI file.
     * The INI file lives in the 'lib' folder of an app, and is named $pkg.ini.php.
     * If the 'lib' folder is writeable, a static copy of the generated code will
     * be saved to lib/_$pkg.php and be loaded next time.  The static copy is
     * automatically regenerated upon any change to the INI file or to this file
     * (Generic.php).
     *
     * The INI file defines which objects to make available, and the relations
     * between them.  For example, for a shopping cart you might define objects for
     * Product, Category, Option, and Order.  The relations might be that a Product
     * belongs to one or more Categories and Orders, and one or more Options belong
     * to a Product.
     *
     * The benefit of using this technique is that it provides convenience methods
     * for controlling the relationships between objects.  Specifically, for each
     * relation, the following three methods are defined (in both directions):
     *
     * - set{Object} (&$Object)
     * - unset{Object} (&$object)
     * - get{Object}s ()
     *
     * Where {Object} is the name of the related object.  So for a Product, you
     * would have setCategory, unsetCategory, getCategories, and so on.  For a
     * Category you would have setProduct, unsetProduct, and getProducts.  However,
     * for Options, since they belong to only one Product, the getProducts method
     * is actually named getProduct and returns just the one Product.
     *
     * Loading packages in this way is also seamlessly integrated into the Loader
     * class as well, simply call:
     *
     * loader_import ('myapp.Objects');
     *
     * And you will have generated and imported the objects defined in
     * inc/app/myapp/lib/Objects.ini.php just like that.
     *
     * The INI format is as follows:
     *
     * <code>
     * ; <?php /*
     *
     * [Product]
     *
     * table = myapp_product
     * pkey = id
     * ;permissions = on ; uncomment this if your table has the sitellte_* fields
     *
     * [Category]
     *
     * table = myapp_category
     * pkey = id
     *
     * [Option]
     *
     * table = myapp_option
     * pkey = id
     *
     * [rel:Product:Category]
     *
     * type = xx ; many-to-many
     * join_table = myapp_product_category
     * Product field = product_id
     * Category field = category_id
     *
     * [rel:Product:Option]
     *
     * type = 1x ; one-to-many
     * Option field = product_id
     * cascade = on ; delete options when product is deleted
     *
     * ; * / ? >
     * </code>
     *
     * Additional relationship types '11' (one-to-one) and 'tree' (via self-
     * referencing columns) are planned to be added in a future release.
     *
     * @access public
     * @param string
     * @param string
     * @return boolean
     */
    function load($app, $pkg)
    {
        $inifile = 'inc/app/' . $app . '/lib/' . $pkg . '.ini.php';
        $codefile = 'inc/app/' . $app . '/lib/_' . $pkg . '.php';
        if (@file_exists($codefile) && filemtime($codefile) >= filemtime($inifile) && filemtime($codefile) >= filemtime(__FILE__)) {
            include_once $codefile;
            return true;
        }
        $spt_header = '{filter none}{import}{end filter}class {class_name} extends {extends} {
	function {class_name} ($id = false) {
		parent::{extends} (\'{table}\', \'{pkey}\');
		{if obj[permissions]}$this->usePermissions = true;{end if}
		{if obj[multilingual]}$this->multilingual = true;{end if}

		if (is_array ($id)) {
			$newkey = $this->add ($id);
			if (is_numeric ($newkey)) {
				$this->setCurrent ($this->get ($newkey));
			} else {
				$this->setCurrent ($this->get ($id[\'{pkey}\']));
			}
		} elseif (is_object ($id)) {
			$this->setCurrent ($id);
		} elseif ($id) {
			$this->setCurrent ($this->get ($id));
		}

		// {class_name} cascade
	}
';
        $spt_xx = '

	function &set{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'insert into {join_table} ({field_one}, {field_two}) values (?, ?)\',
			$this->pkey (),
			$k
		)) {
			$this->error = db_error ();
			return false;
		}
		return $o;
	}

	function unset{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'delete from {join_table} where {field_one} = ? and {field_two} = ?\',
			$this->val (\'{pkey}\'),
			$k
		)) {
			$this->error = db_error ();
			return false;
		}
		return true;
	}

	function get{class_two_pleural} ($id = false) {
		if (! $id) {
			$id = $this->val (\'{pkey}\');
		} elseif (is_object ($id)) {
			$id = $id->{pkey};
		}

		return db_fetch_array (
			\'select b.*, j.* from {table} a, {join_table} j, {table_two} b
			where a.{pkey} = ? and a.{pkey} = j.{field_one} and b.{pkey_two} = j.{field_two}\',
			$id
		);
	}
';
        $spt_1x = '

	function &set{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
			$o->_current->{join_field} = $this->pkey ();
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'update {table_two} set {join_field} = ? where {pkey_two} = ?\',
			$this->pkey (),
			$k
		)) {
			$this->error = db_error ();
			return false;
		}
		return $o;
	}

	function unset{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
			$o->_current->{join_field} = 0;
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'update {table_two} set {join_field} = ? where {pkey_two} = ?\',
			0,
			$k
		)) {
			$this->error = db_error ();
			return false;
		}
		return true;
	}

	function get{class_two_pleural} ($id = false) {
		if (! $id) {
			$id = $this->val (\'{pkey}\');
		} elseif (is_object ($id)) {
			$id = $id->{pkey};
		}

		return db_fetch_array (
			\'select * from {table_two}
			where {join_field} = ?\',
			$id
		);
	}
';
        $spt_x1 = '

	function &set{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'update {table} set {join_field} = ? where {pkey} = ?\',
			$k,
			$this->pkey ()
		)) {
			$this->error = db_error ();
			return false;
		}
		$this->_current->{join_field} = $k;
		return $o;
	}

	function unset{class_two} (&$o) {
		if (is_subclass_of ($o, \'Generic\')) {
			$k = $o->pkey ();
		} else {
			$k = $o->{pkey_two};
		}
		if (! db_execute (
			\'update {table} set {join_field} = ? where {pkey} = ?\',
			0,
			$this->pkey ()
		)) {
			$this->error = db_error ();
			return false;
		}
		$this->_current->{join_field} = 0;
		return true;
	}

	function get{class_two} () {
		return db_single (
			\'select * from {table_two}
			where {pkey_two} = ?\',
			$this->val (\'{join_field}\')
		);
	}
';
        $spt_11 = '

	function &set{class_two} (&$o) {
	}

	function unset{class_two} (&$o) {
	}

	function get{class_two} ($id = false) {
	}
';
        // parse ini file, generate code file, save code file, load code file
        $block = ini_parse($inifile);
        if (!is_array($block)) {
            return false;
        }
        $rels = array();
        $objs = array();
        $code = OPEN_TAG . NEWLINEx2;
        foreach ($block as $name => $info) {
            if (strpos($name, 'rel:') === 0) {
                $rels[$name] = $info;
            } else {
                $objs[$name] = $info;
            }
        }
        foreach ($objs as $name => $info) {
            $info['class_name'] = $name;
            if (!isset($info['extends'])) {
                $info['extends'] = 'Generic';
            }
            if (isset($info['import'])) {
                $info['import'] = 'loader_import (\'' . $info['import'] . "');\n\n";
            } else {
                $info['import'] = '';
            }
            $info['cascade'] = '';
            $code .= template_simple($spt_header, $info);
            foreach ($rels as $k => $v) {
                list($tmp, $class_one, $class_two) = explode(':', $k);
                if ($name == $class_one) {
                    // add relationships to the current object declaration
                    if ($v['cascade']) {
                        $info['cascade'] .= '
		$this->_cascade[\'' . $class_two . '\'] = \'' . $v[$class_two . ' field'] . '\';';
                    } elseif ($v['type'] == 'xx') {
                        $info['cascade'] .= '
		$this->_cascade[] = array (\'' . $v['join_table'] . '\', \'' . $v[$class_one . ' field'] . '\');';
                    }
                    $v['class_one'] = $class_one;
                    $v['class_two'] = $class_two;
                    switch ($v['type']) {
                        case 'xx':
                            $v['class_one_pleural'] = str_replace('ys', 'ies', $class_one . 's');
                            $v['class_two_pleural'] = str_replace('ys', 'ies', $class_two . 's');
                            $v['class_one_pleural'] = preg_replace('/ss$/', 's', $v['class_one_pleural']);
                            $v['class_two_pleural'] = preg_replace('/ss$/', 's', $v['class_two_pleural']);
                            $v['class_one_pleural'] = preg_replace('/xs$/', 'xes', $v['class_one_pleural']);
                            $v['class_two_pleural'] = preg_replace('/xs$/', 'xes', $v['class_two_pleural']);
                            $v['table'] = $objs[$class_one]['table'];
                            $v['pkey'] = $objs[$class_one]['pkey'];
                            $v['table_two'] = $objs[$class_two]['table'];
                            $v['pkey_two'] = $objs[$class_two]['pkey'];
                            $v['field_one'] = $v[$class_one . ' field'];
                            $v['field_two'] = $v[$class_two . ' field'];
                            $code .= template_simple($spt_xx, $v);
                            break;
                        case '1x':
                            $v['class_two_pleural'] = str_replace('ys', 'ies', $class_two . 's');
                            $v['class_two_pleural'] = preg_replace('/ss$/', 's', $v['class_two_pleural']);
                            $v['class_two_pleural'] = preg_replace('/xs$/', 'xes', $v['class_two_pleural']);
                            $v['table'] = $objs[$class_one]['table'];
                            $v['pkey'] = $objs[$class_one]['pkey'];
                            $v['table_two'] = $objs[$class_two]['table'];
                            $v['pkey_two'] = $objs[$class_two]['pkey'];
                            $v['join_field'] = $v[$class_two . ' field'];
                            $code .= template_simple($spt_1x, $v);
                            break;
                        case '11':
                            /*$v['table'] = $objs[$class_one]['table'];
                            		$v['pkey'] = $objs[$class_one]['pkey'];
                            		$v['table_two'] = $objs[$class_two]['table'];
                            		$v['pkey_two'] = $objs[$class_two]['pkey'];
                            		$v['join_field'] = $v[$class_two . ' field'];
                            		$code .= template_simple ($spt_11, $v);*/
                            break;
                        case 'tree':
                            break;
                        default:
                            die('Invalid relationship type in ' . $inifile);
                    }
                } elseif ($name == $class_two) {
                    // add relationships to the current object declaration
                    $tmp = $class_one;
                    $class_one = $class_two;
                    $class_two = $tmp;
                    $v['class_one'] = $class_one;
                    $v['class_two'] = $class_two;
                    switch ($v['type']) {
                        case 'xx':
                            $v['class_one_pleural'] = str_replace('ys', 'ies', $class_one . 's');
                            $v['class_two_pleural'] = str_replace('ys', 'ies', $class_two . 's');
                            $v['class_one_pleural'] = preg_replace('/ss$/', 's', $v['class_one_pleural']);
                            $v['class_two_pleural'] = preg_replace('/ss$/', 's', $v['class_two_pleural']);
                            $v['class_one_pleural'] = preg_replace('/xs$/', 'xes', $v['class_one_pleural']);
                            $v['class_two_pleural'] = preg_replace('/xs$/', 'xes', $v['class_two_pleural']);
                            $v['table'] = $objs[$class_one]['table'];
                            $v['pkey'] = $objs[$class_one]['pkey'];
                            $v['table_two'] = $objs[$class_two]['table'];
                            $v['pkey_two'] = $objs[$class_two]['pkey'];
                            $v['field_one'] = $v[$class_one . ' field'];
                            $v['field_two'] = $v[$class_two . ' field'];
                            $code .= template_simple($spt_xx, $v);
                            break;
                        case '1x':
                            $v['table'] = $objs[$class_one]['table'];
                            $v['pkey'] = $objs[$class_one]['pkey'];
                            $v['table_two'] = $objs[$class_two]['table'];
                            $v['pkey_two'] = $objs[$class_two]['pkey'];
                            $v['join_field'] = $v[$class_one . ' field'];
                            $code .= template_simple($spt_x1, $v);
                            break;
                        case '11':
                            /*$v['table'] = $objs[$class_one]['table'];
                            		$v['pkey'] = $objs[$class_one]['pkey'];
                            		$v['table_two'] = $objs[$class_two]['table'];
                            		$v['pkey_two'] = $objs[$class_two]['pkey'];
                            		$v['join_field'] = $v[$class_two . ' field'];
                            		$code .= template_simple ($spt_11, $v);*/
                            break;
                        case 'tree':
                            break;
                        default:
                            die('Invalid relationship type in ' . $inifile);
                    }
                }
            }
            if (!empty($info['cascade'])) {
                $code = str_replace("\t\t// " . $info['class_name'] . ' cascade', $info['cascade'], $code);
            }
            $code .= '}' . NEWLINEx2;
        }
        $code .= CLOSE_TAG;
        if (!@file_exists($codefile) && is_writeable(dirname($codefile)) || @is_writeable($codefile)) {
            loader_import('saf.File');
            file_overwrite($codefile, $code);
            umask(00);
            @chmod($codefile, 0777);
            include_once $codefile;
            return true;
        } else {
            eval(CLOSE_TAG . $code);
            return true;
        }
    }
Esempio n. 27
0
    $app = 'GLOBAL';
    $read = 'inc/html';
    $write = 'inc/lang/index.php';
    $list = 'inc/lang/languages.php';
    $langs = 'inc/lang';
    $info = array('app_name' => 'Global');
} elseif (empty($parameters['appname']) || strstr($parameters['appname'], '..') || !@is_dir(getcwd() . '/inc/app/' . $parameters['appname'])) {
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit;
} else {
    $app = $parameters['appname'];
    $read = 'inc/app/' . $app;
    $write = 'inc/app/' . $app . '/lang/index.php';
    $list = 'inc/app/' . $app . '/lang/languages.php';
    $langs = 'inc/app/' . $app . '/lang';
    $info = ini_parse(getcwd() . '/inc/app/' . $app . '/conf/config.ini.php', false);
}
if (!@is_dir($read)) {
    die('No app folder found.');
}
if (!@is_dir($langs)) {
    $r = mkdir($langs, 0777);
    if (!$r) {
        die('No lang folder found.  Attempt to create failed.');
    }
}
if (!@is_writeable($langs)) {
    die('Cannot write to langs folder.  Please change your filesystem permissions.');
}
if (!@file_exists($list)) {
    loader_import('saf.File');
Esempio n. 28
0
 /**
  * Retrieves the data from $file and stores it in $data.
  */
 function getData()
 {
     $this->data = ini_parse($this->file, false);
 }
Esempio n. 29
0
foreach (Dir::fetch('inc/app/cms/conf/collections') as $file) {
    if (strpos($file, '.') === 0 || @is_dir('inc/app/cms/conf/collections/' . $file)) {
        continue;
    }
    $config = ini_parse('inc/app/cms/conf/collections/' . $file);
    if (isset($config['Collection']['sitesearch_url'])) {
        if (isset($config['Collection']['sitesearch_access']) && session_allowed($config['Collection']['sitesearch_access'], 'r', 'access')) {
            $sitesearch_allowed[] = $config['Collection']['name'];
        }
        $sitesearch_highlight[$config['Collection']['name']] = $config['Collection']['name'];
        if (isset($config['Collection']['sitesearch_highlight']) && !$config['Collection']['sitesearch_highlight']) {
            unset($sitesearch_highlight[$config['Collection']['name']]);
        }
    }
}
$folders = ini_parse('inc/app/sitesearch/conf/folders.ini.php');
$domains = array(site_domain() => site_domain());
foreach ($folders as $name => $folder) {
    if (isset($folder['domain'])) {
        $domains[$folder['domain']] = $folder['domain'];
    } else {
        $sitesearch_allowed[] = $name;
    }
}
if (!empty($parameters['query'])) {
    loader_import('sitesearch.SiteSearch');
    $searcher = new SiteSearch();
    if (is_array($parameters['ctype'])) {
        $collections = $parameters['ctype'];
        foreach ($collections as $k => $ctype) {
            if (!in_array($ctype, $sitesearch_allowed)) {
Esempio n. 30
0
 /**
  * Determines which template to use to render the document for output
  * to the visitor.  The template is chosen based on the following
  * conditions:
  *
  * - Templates all live in inc/html in individual template set directories
  *   (ie. themes).  The template set can be specified with page_template_set(),
  *   or via the default_template_set configuration option.
  * - The $cgi->mode value, which defaults to "html" if unspecified
  * - The $template property of this object is appended to the mode like
  *   this: html.index.tpl where html is the mode and index is the $template
  *   value.  The template can be specified with the page_template() function,
  *   or via the default_template configuration option.
  * - If that document is not found, we then check for such a document
  *   based on the names of parent documents in the hierarchy, but only
  *   those that are designated as section roots.  Each of these is then
  *   used as a replacement for the $template property.
  * - If none is found, then the default html.{default_template}.tpl is used,
  *   where html is the mode.
  *
  * Note that the templates are always in XT format.  For info on the XT template
  * language, see the class documentation under XML/XT at sitellite.org/docs
  *
  * @return string
  */
 function useTemplate()
 {
     global $tpl, $cgi, $menu, $conf;
     if ($this->template_set) {
         $set = $this->template_set;
     } else {
         $set = $conf['Server']['default_template_set'];
     }
     $old_path = $tpl->path;
     $tpl->path = $tpl->path . '/' . $set;
     if (@file_exists($tpl->path . '/modes.php')) {
         $modes = ini_parse($tpl->path . '/modes.php');
         if (isset($modes[$cgi->mode]['content_type'])) {
             global $intl;
             if (!empty($intl->charset)) {
                 header('Content-Type: ' . $modes[$cgi->mode]['content_type'] . '; charset=' . $intl->charset);
             } else {
                 header('Content-Type: ' . $modes[$cgi->mode]['content_type']);
             }
         }
         if (is_array($modes[$cgi->mode])) {
             foreach ($modes[$cgi->mode] as $k => $v) {
                 if (strpos($k, 'filter ') === 0) {
                     list($field, $filter) = preg_split('/: ?/', $v);
                     if ($field == 'final') {
                         $final = false;
                         if (strstr($filter, '.')) {
                             // it's a package, needs inclusion first
                             $filter_name = strtolower(str_replace('.', '_', $filter)) . '_content_filter';
                             if (loader_import($filter)) {
                                 if (function_exists($filter_name)) {
                                     $final = $filter_name;
                                 }
                             }
                         } else {
                             // it's an ordinary function
                             $final = $filter;
                         }
                     } else {
                         if (strstr($filter, '.')) {
                             // it's a package, needs inclusion first
                             $filter_name = strtolower(str_replace('.', '_', $filter)) . '_content_filter';
                             if (loader_import($filter)) {
                                 if (function_exists($filter_name)) {
                                     $this->{$field} = $filter_name($this->{$field});
                                 }
                             }
                         } else {
                             // it's an ordinary function
                             $this->{$field} = $filter($this->{$field});
                         }
                     }
                 }
             }
         }
     } else {
         $modes = array('html' => array('content_type' => 'text/html'));
     }
     if ($cgi->mode == 'html') {
         foreach ($modes as $k => $m) {
             if ($k != 'html') {
                 $alt_url = $_SERVER['REQUEST_URI'];
                 if (strpos($alt_url, '?') !== false) {
                     $alt_url = str_replace('?', '/mode.' . $k . '?', $alt_url);
                 } else {
                     $alt_url .= '/mode.' . $k;
                 }
                 page_add_link('alternate', $m['content_type'], $alt_url);
             }
         }
     }
     if (!empty($this->template) && @file_exists(getcwd() . '/' . $tpl->path . '/' . $cgi->mode . '.' . $this->template . '.tpl')) {
         $response = $tpl->fill($cgi->mode . '.' . $this->template . '.tpl', $this);
         $_t = $cgi->mode . '.' . $this->template . '.tpl';
     } elseif (!empty($this->below_page)) {
         // inherit section template
         loader_box('sitellite/nav/init');
         $useTemplate = false;
         $parent = $this->below_page;
         while (true) {
             // is_object ($menu->{'items_' . $parent})) {
             if ($menu->{'items_' . $parent}->is_section && $menu->{'items_' . $parent}->template && @file_exists(getcwd() . '/' . $tpl->path . '/' . $cgi->mode . '.' . $menu->{'items_' . $parent}->template . '.tpl')) {
                 $useTemplate = $menu->{'items_' . $parent}->template;
                 break;
             } elseif (is_object($menu->{'items_' . $parent}->parent)) {
                 $parent = $menu->{'items_' . $parent}->parent->id;
             } else {
                 break;
             }
         }
         if ($useTemplate) {
             $response = $tpl->fill($cgi->mode . '.' . $useTemplate . '.tpl', $this);
             $_t = $cgi->mode . '_' . $useTemplate . '.tpl';
         } elseif (!empty($conf['Server']['default_template']) && @file_exists(getcwd() . '/' . $tpl->path . '/' . $cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl')) {
             $response = $tpl->fill($cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl', $this);
             $_t = $cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl';
         } else {
             $response = $tpl->fill($cgi->mode . '.default.tpl', $this);
             $_t = $cgi->mode . '.default.tpl';
         }
     } elseif (!empty($conf['Server']['default_template']) && @file_exists(getcwd() . '/' . $tpl->path . '/' . $cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl')) {
         $response = $tpl->fill($cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl', $this);
         $_t = $cgi->mode . '.' . $conf['Server']['default_template'] . '.tpl';
     } else {
         $response = $tpl->fill($cgi->mode . '.default.tpl', $this);
         $_t = $cgi->mode . '.default.tpl';
     }
     if ($response === false) {
         $response = '<p>' . $tpl->error . ' (Template: ' . $_t . ', Line ' . $tpl->err_line . ', Column ' . $tpl->err_colnum . ')</p>';
     }
     if ($final) {
         $response = $final($response);
     }
     $tpl->path = $old_path;
     return $response;
 }